
_test2:     file format elf32-i386


Disassembly of section .text:

00000000 <barrier_init>:
#include "uthread.h"
#include "barrier.h"


void barrier_init(struct barrier *bar, int num)
{
       0:	55                   	push   %ebp
       1:	89 e5                	mov    %esp,%ebp
       3:	83 ec 18             	sub    $0x18,%esp
	bar->n = num;
       6:	8b 45 08             	mov    0x8(%ebp),%eax
       9:	8b 55 0c             	mov    0xc(%ebp),%edx
       c:	89 10                	mov    %edx,(%eax)
	bar->counter = 0;
       e:	8b 45 08             	mov    0x8(%ebp),%eax
      11:	c7 40 04 00 00 00 00 	movl   $0x0,0x4(%eax)
	bar->arrival = malloc(sizeof(struct binary_semaphore));
      18:	c7 04 24 08 00 00 00 	movl   $0x8,(%esp)
      1f:	e8 11 0a 00 00       	call   a35 <malloc>
      24:	8b 55 08             	mov    0x8(%ebp),%edx
      27:	89 42 08             	mov    %eax,0x8(%edx)
	bar->departure = malloc(sizeof(struct binary_semaphore));
      2a:	c7 04 24 08 00 00 00 	movl   $0x8,(%esp)
      31:	e8 ff 09 00 00       	call   a35 <malloc>
      36:	8b 55 08             	mov    0x8(%ebp),%edx
      39:	89 42 0c             	mov    %eax,0xc(%edx)
	binary_semaphore_init(bar->arrival, 1);
      3c:	8b 45 08             	mov    0x8(%ebp),%eax
      3f:	8b 40 08             	mov    0x8(%eax),%eax
      42:	c7 44 24 04 01 00 00 	movl   $0x1,0x4(%esp)
      49:	00 
      4a:	89 04 24             	mov    %eax,(%esp)
      4d:	e8 5b 10 00 00       	call   10ad <binary_semaphore_init>
	binary_semaphore_init(bar->departure, 0);
      52:	8b 45 08             	mov    0x8(%ebp),%eax
      55:	8b 40 0c             	mov    0xc(%eax),%eax
      58:	c7 44 24 04 00 00 00 	movl   $0x0,0x4(%esp)
      5f:	00 
      60:	89 04 24             	mov    %eax,(%esp)
      63:	e8 45 10 00 00       	call   10ad <binary_semaphore_init>
}
      68:	c9                   	leave  
      69:	c3                   	ret    

0000006a <barrier_pass>:

void barrier_pass(struct barrier *bar)
{
      6a:	55                   	push   %ebp
      6b:	89 e5                	mov    %esp,%ebp
      6d:	83 ec 18             	sub    $0x18,%esp
	binary_semaphore_down(bar->arrival);
      70:	8b 45 08             	mov    0x8(%ebp),%eax
      73:	8b 40 08             	mov    0x8(%eax),%eax
      76:	89 04 24             	mov    %eax,(%esp)
      79:	e8 64 10 00 00       	call   10e2 <binary_semaphore_down>
	bar->counter++;
      7e:	8b 45 08             	mov    0x8(%ebp),%eax
      81:	8b 40 04             	mov    0x4(%eax),%eax
      84:	8d 50 01             	lea    0x1(%eax),%edx
      87:	8b 45 08             	mov    0x8(%ebp),%eax
      8a:	89 50 04             	mov    %edx,0x4(%eax)
	if (bar->counter < bar->n)
      8d:	8b 45 08             	mov    0x8(%ebp),%eax
      90:	8b 50 04             	mov    0x4(%eax),%edx
      93:	8b 45 08             	mov    0x8(%ebp),%eax
      96:	8b 00                	mov    (%eax),%eax
      98:	39 c2                	cmp    %eax,%edx
      9a:	7d 10                	jge    ac <barrier_pass+0x42>
		binary_semaphore_up(bar->arrival);
      9c:	8b 45 08             	mov    0x8(%ebp),%eax
      9f:	8b 40 08             	mov    0x8(%eax),%eax
      a2:	89 04 24             	mov    %eax,(%esp)
      a5:	e8 92 10 00 00       	call   113c <binary_semaphore_up>
      aa:	eb 0e                	jmp    ba <barrier_pass+0x50>
	else
		binary_semaphore_up(bar->departure);
      ac:	8b 45 08             	mov    0x8(%ebp),%eax
      af:	8b 40 0c             	mov    0xc(%eax),%eax
      b2:	89 04 24             	mov    %eax,(%esp)
      b5:	e8 82 10 00 00       	call   113c <binary_semaphore_up>
	binary_semaphore_down(bar->departure);
      ba:	8b 45 08             	mov    0x8(%ebp),%eax
      bd:	8b 40 0c             	mov    0xc(%eax),%eax
      c0:	89 04 24             	mov    %eax,(%esp)
      c3:	e8 1a 10 00 00       	call   10e2 <binary_semaphore_down>
	bar->counter--;
      c8:	8b 45 08             	mov    0x8(%ebp),%eax
      cb:	8b 40 04             	mov    0x4(%eax),%eax
      ce:	8d 50 ff             	lea    -0x1(%eax),%edx
      d1:	8b 45 08             	mov    0x8(%ebp),%eax
      d4:	89 50 04             	mov    %edx,0x4(%eax)
	if (bar->counter > 0)
      d7:	8b 45 08             	mov    0x8(%ebp),%eax
      da:	8b 40 04             	mov    0x4(%eax),%eax
      dd:	85 c0                	test   %eax,%eax
      df:	7e 10                	jle    f1 <barrier_pass+0x87>
		binary_semaphore_up(bar->departure);
      e1:	8b 45 08             	mov    0x8(%ebp),%eax
      e4:	8b 40 0c             	mov    0xc(%eax),%eax
      e7:	89 04 24             	mov    %eax,(%esp)
      ea:	e8 4d 10 00 00       	call   113c <binary_semaphore_up>
      ef:	eb 0e                	jmp    ff <barrier_pass+0x95>
	else
		binary_semaphore_up(bar->arrival);
      f1:	8b 45 08             	mov    0x8(%ebp),%eax
      f4:	8b 40 08             	mov    0x8(%eax),%eax
      f7:	89 04 24             	mov    %eax,(%esp)
      fa:	e8 3d 10 00 00       	call   113c <binary_semaphore_up>
}
      ff:	c9                   	leave  
     100:	c3                   	ret    

00000101 <work2>:
void print_num(void *num);
void work();


void work2(void *arg)
{
     101:	55                   	push   %ebp
     102:	89 e5                	mov    %esp,%ebp
     104:	83 ec 28             	sub    $0x28,%esp
	int i = banana[uthread_self()%10];
     107:	e8 f4 0d 00 00       	call   f00 <uthread_self>
     10c:	89 c1                	mov    %eax,%ecx
     10e:	ba 67 66 66 66       	mov    $0x66666667,%edx
     113:	89 c8                	mov    %ecx,%eax
     115:	f7 ea                	imul   %edx
     117:	c1 fa 02             	sar    $0x2,%edx
     11a:	89 c8                	mov    %ecx,%eax
     11c:	c1 f8 1f             	sar    $0x1f,%eax
     11f:	29 c2                	sub    %eax,%edx
     121:	89 d0                	mov    %edx,%eax
     123:	c1 e0 02             	shl    $0x2,%eax
     126:	01 d0                	add    %edx,%eax
     128:	01 c0                	add    %eax,%eax
     12a:	89 ca                	mov    %ecx,%edx
     12c:	29 c2                	sub    %eax,%edx
     12e:	8b 04 95 60 17 00 00 	mov    0x1760(,%edx,4),%eax
     135:	89 45 f4             	mov    %eax,-0xc(%ebp)
	barrier_pass(&bar);
     138:	c7 04 24 88 17 00 00 	movl   $0x1788,(%esp)
     13f:	e8 26 ff ff ff       	call   6a <barrier_pass>
	banana[(uthread_self()-1)%10] = i+1;
     144:	e8 b7 0d 00 00       	call   f00 <uthread_self>
     149:	8d 48 ff             	lea    -0x1(%eax),%ecx
     14c:	ba 67 66 66 66       	mov    $0x66666667,%edx
     151:	89 c8                	mov    %ecx,%eax
     153:	f7 ea                	imul   %edx
     155:	c1 fa 02             	sar    $0x2,%edx
     158:	89 c8                	mov    %ecx,%eax
     15a:	c1 f8 1f             	sar    $0x1f,%eax
     15d:	29 c2                	sub    %eax,%edx
     15f:	89 d0                	mov    %edx,%eax
     161:	c1 e0 02             	shl    $0x2,%eax
     164:	01 d0                	add    %edx,%eax
     166:	01 c0                	add    %eax,%eax
     168:	89 ca                	mov    %ecx,%edx
     16a:	29 c2                	sub    %eax,%edx
     16c:	8b 45 f4             	mov    -0xc(%ebp),%eax
     16f:	83 c0 01             	add    $0x1,%eax
     172:	89 04 95 60 17 00 00 	mov    %eax,0x1760(,%edx,4)
	barrier_pass(&bar2);
     179:	c7 04 24 98 17 00 00 	movl   $0x1798,(%esp)
     180:	e8 e5 fe ff ff       	call   6a <barrier_pass>
}
     185:	c9                   	leave  
     186:	c3                   	ret    

00000187 <main>:

int main(void)
{
     187:	55                   	push   %ebp
     188:	89 e5                	mov    %esp,%ebp
     18a:	83 e4 f0             	and    $0xfffffff0,%esp
     18d:	83 ec 20             	sub    $0x20,%esp
  int i;


  uthread_init();
     190:	e8 83 09 00 00       	call   b18 <uthread_init>
  barrier_init(&bar, 10);
     195:	c7 44 24 04 0a 00 00 	movl   $0xa,0x4(%esp)
     19c:	00 
     19d:	c7 04 24 88 17 00 00 	movl   $0x1788,(%esp)
     1a4:	e8 57 fe ff ff       	call   0 <barrier_init>
  printf(1, "\ngot here1\n");
     1a9:	c7 44 24 04 98 11 00 	movl   $0x1198,0x4(%esp)
     1b0:	00 
     1b1:	c7 04 24 01 00 00 00 	movl   $0x1,(%esp)
     1b8:	e8 88 05 00 00       	call   745 <printf>
  barrier_init(&bar2, 11);
     1bd:	c7 44 24 04 0b 00 00 	movl   $0xb,0x4(%esp)
     1c4:	00 
     1c5:	c7 04 24 98 17 00 00 	movl   $0x1798,(%esp)
     1cc:	e8 2f fe ff ff       	call   0 <barrier_init>
  printf(1, "\ngot here2\n");
     1d1:	c7 44 24 04 a4 11 00 	movl   $0x11a4,0x4(%esp)
     1d8:	00 
     1d9:	c7 04 24 01 00 00 00 	movl   $0x1,(%esp)
     1e0:	e8 60 05 00 00       	call   745 <printf>
  //binary_semaphore_init(&semaphore, 1);
  for (i = 0; i < 10; i++)
     1e5:	c7 44 24 1c 00 00 00 	movl   $0x0,0x1c(%esp)
     1ec:	00 
     1ed:	eb 19                	jmp    208 <main+0x81>
  {
	  uthread_create(work2, 0);
     1ef:	c7 44 24 04 00 00 00 	movl   $0x0,0x4(%esp)
     1f6:	00 
     1f7:	c7 04 24 01 01 00 00 	movl   $0x101,(%esp)
     1fe:	e8 a4 09 00 00       	call   ba7 <uthread_create>
  barrier_init(&bar, 10);
  printf(1, "\ngot here1\n");
  barrier_init(&bar2, 11);
  printf(1, "\ngot here2\n");
  //binary_semaphore_init(&semaphore, 1);
  for (i = 0; i < 10; i++)
     203:	83 44 24 1c 01       	addl   $0x1,0x1c(%esp)
     208:	83 7c 24 1c 09       	cmpl   $0x9,0x1c(%esp)
     20d:	7e e0                	jle    1ef <main+0x68>
  {
	  uthread_create(work2, 0);
  }
  printf(1, "\ngot here3\n");
     20f:	c7 44 24 04 b0 11 00 	movl   $0x11b0,0x4(%esp)
     216:	00 
     217:	c7 04 24 01 00 00 00 	movl   $0x1,(%esp)
     21e:	e8 22 05 00 00       	call   745 <printf>
  //printf(1,"\ntook over\n");

  barrier_pass(&bar2);
     223:	c7 04 24 98 17 00 00 	movl   $0x1798,(%esp)
     22a:	e8 3b fe ff ff       	call   6a <barrier_pass>
  printf(1, "\ngot here4\n");
     22f:	c7 44 24 04 bc 11 00 	movl   $0x11bc,0x4(%esp)
     236:	00 
     237:	c7 04 24 01 00 00 00 	movl   $0x1,(%esp)
     23e:	e8 02 05 00 00       	call   745 <printf>
  for (i = 0; i < 10; i++)
     243:	c7 44 24 1c 00 00 00 	movl   $0x0,0x1c(%esp)
     24a:	00 
     24b:	eb 28                	jmp    275 <main+0xee>
	  printf(1, "%d\n",banana[i]);
     24d:	8b 44 24 1c          	mov    0x1c(%esp),%eax
     251:	8b 04 85 60 17 00 00 	mov    0x1760(,%eax,4),%eax
     258:	89 44 24 08          	mov    %eax,0x8(%esp)
     25c:	c7 44 24 04 c8 11 00 	movl   $0x11c8,0x4(%esp)
     263:	00 
     264:	c7 04 24 01 00 00 00 	movl   $0x1,(%esp)
     26b:	e8 d5 04 00 00       	call   745 <printf>
  printf(1, "\ngot here3\n");
  //printf(1,"\ntook over\n");

  barrier_pass(&bar2);
  printf(1, "\ngot here4\n");
  for (i = 0; i < 10; i++)
     270:	83 44 24 1c 01       	addl   $0x1,0x1c(%esp)
     275:	83 7c 24 1c 09       	cmpl   $0x9,0x1c(%esp)
     27a:	7e d1                	jle    24d <main+0xc6>
	  printf(1, "%d\n",banana[i]);
  printf(1, "\ngot here5\n");
     27c:	c7 44 24 04 cc 11 00 	movl   $0x11cc,0x4(%esp)
     283:	00 
     284:	c7 04 24 01 00 00 00 	movl   $0x1,(%esp)
     28b:	e8 b5 04 00 00       	call   745 <printf>
  uthread_exit();
     290:	e8 fc 0b 00 00       	call   e91 <uthread_exit>

  exit();
     295:	e8 0e 03 00 00       	call   5a8 <exit>

0000029a <work>:
}

void work()
{
     29a:	55                   	push   %ebp
     29b:	89 e5                	mov    %esp,%ebp
     29d:	83 ec 28             	sub    $0x28,%esp
	int i;
	int tid = uthread_self();
     2a0:	e8 5b 0c 00 00       	call   f00 <uthread_self>
     2a5:	89 45 f0             	mov    %eax,-0x10(%ebp)
	for (i = 0; i < 10; i++)
     2a8:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
     2af:	eb 26                	jmp    2d7 <work+0x3d>
		printf(1,"Thread %d's print number %d\n", tid,i);
     2b1:	8b 45 f4             	mov    -0xc(%ebp),%eax
     2b4:	89 44 24 0c          	mov    %eax,0xc(%esp)
     2b8:	8b 45 f0             	mov    -0x10(%ebp),%eax
     2bb:	89 44 24 08          	mov    %eax,0x8(%esp)
     2bf:	c7 44 24 04 d8 11 00 	movl   $0x11d8,0x4(%esp)
     2c6:	00 
     2c7:	c7 04 24 01 00 00 00 	movl   $0x1,(%esp)
     2ce:	e8 72 04 00 00       	call   745 <printf>

void work()
{
	int i;
	int tid = uthread_self();
	for (i = 0; i < 10; i++)
     2d3:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
     2d7:	83 7d f4 09          	cmpl   $0x9,-0xc(%ebp)
     2db:	7e d4                	jle    2b1 <work+0x17>
		printf(1,"Thread %d's print number %d\n", tid,i);
	//binary_semaphore_down(&semaphore);
	for (i = 10; i < 20; i++)
     2dd:	c7 45 f4 0a 00 00 00 	movl   $0xa,-0xc(%ebp)
     2e4:	eb 26                	jmp    30c <work+0x72>
		printf(1,"Thread %d's print number %d\n", tid,i);
     2e6:	8b 45 f4             	mov    -0xc(%ebp),%eax
     2e9:	89 44 24 0c          	mov    %eax,0xc(%esp)
     2ed:	8b 45 f0             	mov    -0x10(%ebp),%eax
     2f0:	89 44 24 08          	mov    %eax,0x8(%esp)
     2f4:	c7 44 24 04 d8 11 00 	movl   $0x11d8,0x4(%esp)
     2fb:	00 
     2fc:	c7 04 24 01 00 00 00 	movl   $0x1,(%esp)
     303:	e8 3d 04 00 00       	call   745 <printf>
	int i;
	int tid = uthread_self();
	for (i = 0; i < 10; i++)
		printf(1,"Thread %d's print number %d\n", tid,i);
	//binary_semaphore_down(&semaphore);
	for (i = 10; i < 20; i++)
     308:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
     30c:	83 7d f4 13          	cmpl   $0x13,-0xc(%ebp)
     310:	7e d4                	jle    2e6 <work+0x4c>
		printf(1,"Thread %d's print number %d\n", tid,i);
	//binary_semaphore_up(&semaphore);
}
     312:	c9                   	leave  
     313:	c3                   	ret    

00000314 <print_num>:

void print_num(void *num)
{
     314:	55                   	push   %ebp
     315:	89 e5                	mov    %esp,%ebp
     317:	83 ec 28             	sub    $0x28,%esp
	int *i = num;
     31a:	8b 45 08             	mov    0x8(%ebp),%eax
     31d:	89 45 f4             	mov    %eax,-0xc(%ebp)
    printf(1,"\nIf we're all good num is: %d\n", *i);
     320:	8b 45 f4             	mov    -0xc(%ebp),%eax
     323:	8b 00                	mov    (%eax),%eax
     325:	89 44 24 08          	mov    %eax,0x8(%esp)
     329:	c7 44 24 04 f8 11 00 	movl   $0x11f8,0x4(%esp)
     330:	00 
     331:	c7 04 24 01 00 00 00 	movl   $0x1,(%esp)
     338:	e8 08 04 00 00       	call   745 <printf>
}
     33d:	c9                   	leave  
     33e:	c3                   	ret    
     33f:	90                   	nop

00000340 <stosb>:
               "cc");
}

static inline void
stosb(void *addr, int data, int cnt)
{
     340:	55                   	push   %ebp
     341:	89 e5                	mov    %esp,%ebp
     343:	57                   	push   %edi
     344:	53                   	push   %ebx
  asm volatile("cld; rep stosb" :
     345:	8b 4d 08             	mov    0x8(%ebp),%ecx
     348:	8b 55 10             	mov    0x10(%ebp),%edx
     34b:	8b 45 0c             	mov    0xc(%ebp),%eax
     34e:	89 cb                	mov    %ecx,%ebx
     350:	89 df                	mov    %ebx,%edi
     352:	89 d1                	mov    %edx,%ecx
     354:	fc                   	cld    
     355:	f3 aa                	rep stos %al,%es:(%edi)
     357:	89 ca                	mov    %ecx,%edx
     359:	89 fb                	mov    %edi,%ebx
     35b:	89 5d 08             	mov    %ebx,0x8(%ebp)
     35e:	89 55 10             	mov    %edx,0x10(%ebp)
               "=D" (addr), "=c" (cnt) :
               "0" (addr), "1" (cnt), "a" (data) :
               "memory", "cc");
}
     361:	5b                   	pop    %ebx
     362:	5f                   	pop    %edi
     363:	5d                   	pop    %ebp
     364:	c3                   	ret    

00000365 <strcpy>:
#include "user.h"
#include "x86.h"

char*
strcpy(char *s, char *t)
{
     365:	55                   	push   %ebp
     366:	89 e5                	mov    %esp,%ebp
     368:	83 ec 10             	sub    $0x10,%esp
  char *os;

  os = s;
     36b:	8b 45 08             	mov    0x8(%ebp),%eax
     36e:	89 45 fc             	mov    %eax,-0x4(%ebp)
  while((*s++ = *t++) != 0)
     371:	90                   	nop
     372:	8b 45 0c             	mov    0xc(%ebp),%eax
     375:	0f b6 10             	movzbl (%eax),%edx
     378:	8b 45 08             	mov    0x8(%ebp),%eax
     37b:	88 10                	mov    %dl,(%eax)
     37d:	8b 45 08             	mov    0x8(%ebp),%eax
     380:	0f b6 00             	movzbl (%eax),%eax
     383:	84 c0                	test   %al,%al
     385:	0f 95 c0             	setne  %al
     388:	83 45 08 01          	addl   $0x1,0x8(%ebp)
     38c:	83 45 0c 01          	addl   $0x1,0xc(%ebp)
     390:	84 c0                	test   %al,%al
     392:	75 de                	jne    372 <strcpy+0xd>
    ;
  return os;
     394:	8b 45 fc             	mov    -0x4(%ebp),%eax
}
     397:	c9                   	leave  
     398:	c3                   	ret    

00000399 <strcmp>:

int
strcmp(const char *p, const char *q)
{
     399:	55                   	push   %ebp
     39a:	89 e5                	mov    %esp,%ebp
  while(*p && *p == *q)
     39c:	eb 08                	jmp    3a6 <strcmp+0xd>
    p++, q++;
     39e:	83 45 08 01          	addl   $0x1,0x8(%ebp)
     3a2:	83 45 0c 01          	addl   $0x1,0xc(%ebp)
}

int
strcmp(const char *p, const char *q)
{
  while(*p && *p == *q)
     3a6:	8b 45 08             	mov    0x8(%ebp),%eax
     3a9:	0f b6 00             	movzbl (%eax),%eax
     3ac:	84 c0                	test   %al,%al
     3ae:	74 10                	je     3c0 <strcmp+0x27>
     3b0:	8b 45 08             	mov    0x8(%ebp),%eax
     3b3:	0f b6 10             	movzbl (%eax),%edx
     3b6:	8b 45 0c             	mov    0xc(%ebp),%eax
     3b9:	0f b6 00             	movzbl (%eax),%eax
     3bc:	38 c2                	cmp    %al,%dl
     3be:	74 de                	je     39e <strcmp+0x5>
    p++, q++;
  return (uchar)*p - (uchar)*q;
     3c0:	8b 45 08             	mov    0x8(%ebp),%eax
     3c3:	0f b6 00             	movzbl (%eax),%eax
     3c6:	0f b6 d0             	movzbl %al,%edx
     3c9:	8b 45 0c             	mov    0xc(%ebp),%eax
     3cc:	0f b6 00             	movzbl (%eax),%eax
     3cf:	0f b6 c0             	movzbl %al,%eax
     3d2:	89 d1                	mov    %edx,%ecx
     3d4:	29 c1                	sub    %eax,%ecx
     3d6:	89 c8                	mov    %ecx,%eax
}
     3d8:	5d                   	pop    %ebp
     3d9:	c3                   	ret    

000003da <strlen>:

uint
strlen(char *s)
{
     3da:	55                   	push   %ebp
     3db:	89 e5                	mov    %esp,%ebp
     3dd:	83 ec 10             	sub    $0x10,%esp
  int n;

  for(n = 0; s[n]; n++)
     3e0:	c7 45 fc 00 00 00 00 	movl   $0x0,-0x4(%ebp)
     3e7:	eb 04                	jmp    3ed <strlen+0x13>
     3e9:	83 45 fc 01          	addl   $0x1,-0x4(%ebp)
     3ed:	8b 55 fc             	mov    -0x4(%ebp),%edx
     3f0:	8b 45 08             	mov    0x8(%ebp),%eax
     3f3:	01 d0                	add    %edx,%eax
     3f5:	0f b6 00             	movzbl (%eax),%eax
     3f8:	84 c0                	test   %al,%al
     3fa:	75 ed                	jne    3e9 <strlen+0xf>
    ;
  return n;
     3fc:	8b 45 fc             	mov    -0x4(%ebp),%eax
}
     3ff:	c9                   	leave  
     400:	c3                   	ret    

00000401 <memset>:

void*
memset(void *dst, int c, uint n)
{
     401:	55                   	push   %ebp
     402:	89 e5                	mov    %esp,%ebp
     404:	83 ec 0c             	sub    $0xc,%esp
  stosb(dst, c, n);
     407:	8b 45 10             	mov    0x10(%ebp),%eax
     40a:	89 44 24 08          	mov    %eax,0x8(%esp)
     40e:	8b 45 0c             	mov    0xc(%ebp),%eax
     411:	89 44 24 04          	mov    %eax,0x4(%esp)
     415:	8b 45 08             	mov    0x8(%ebp),%eax
     418:	89 04 24             	mov    %eax,(%esp)
     41b:	e8 20 ff ff ff       	call   340 <stosb>
  return dst;
     420:	8b 45 08             	mov    0x8(%ebp),%eax
}
     423:	c9                   	leave  
     424:	c3                   	ret    

00000425 <strchr>:

char*
strchr(const char *s, char c)
{
     425:	55                   	push   %ebp
     426:	89 e5                	mov    %esp,%ebp
     428:	83 ec 04             	sub    $0x4,%esp
     42b:	8b 45 0c             	mov    0xc(%ebp),%eax
     42e:	88 45 fc             	mov    %al,-0x4(%ebp)
  for(; *s; s++)
     431:	eb 14                	jmp    447 <strchr+0x22>
    if(*s == c)
     433:	8b 45 08             	mov    0x8(%ebp),%eax
     436:	0f b6 00             	movzbl (%eax),%eax
     439:	3a 45 fc             	cmp    -0x4(%ebp),%al
     43c:	75 05                	jne    443 <strchr+0x1e>
      return (char*)s;
     43e:	8b 45 08             	mov    0x8(%ebp),%eax
     441:	eb 13                	jmp    456 <strchr+0x31>
}

char*
strchr(const char *s, char c)
{
  for(; *s; s++)
     443:	83 45 08 01          	addl   $0x1,0x8(%ebp)
     447:	8b 45 08             	mov    0x8(%ebp),%eax
     44a:	0f b6 00             	movzbl (%eax),%eax
     44d:	84 c0                	test   %al,%al
     44f:	75 e2                	jne    433 <strchr+0xe>
    if(*s == c)
      return (char*)s;
  return 0;
     451:	b8 00 00 00 00       	mov    $0x0,%eax
}
     456:	c9                   	leave  
     457:	c3                   	ret    

00000458 <gets>:

char*
gets(char *buf, int max)
{
     458:	55                   	push   %ebp
     459:	89 e5                	mov    %esp,%ebp
     45b:	83 ec 28             	sub    $0x28,%esp
  int i, cc;
  char c;

  for(i=0; i+1 < max; ){
     45e:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
     465:	eb 46                	jmp    4ad <gets+0x55>
    cc = read(0, &c, 1);
     467:	c7 44 24 08 01 00 00 	movl   $0x1,0x8(%esp)
     46e:	00 
     46f:	8d 45 ef             	lea    -0x11(%ebp),%eax
     472:	89 44 24 04          	mov    %eax,0x4(%esp)
     476:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
     47d:	e8 3e 01 00 00       	call   5c0 <read>
     482:	89 45 f0             	mov    %eax,-0x10(%ebp)
    if(cc < 1)
     485:	83 7d f0 00          	cmpl   $0x0,-0x10(%ebp)
     489:	7e 2f                	jle    4ba <gets+0x62>
      break;
    buf[i++] = c;
     48b:	8b 55 f4             	mov    -0xc(%ebp),%edx
     48e:	8b 45 08             	mov    0x8(%ebp),%eax
     491:	01 c2                	add    %eax,%edx
     493:	0f b6 45 ef          	movzbl -0x11(%ebp),%eax
     497:	88 02                	mov    %al,(%edx)
     499:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
    if(c == '\n' || c == '\r')
     49d:	0f b6 45 ef          	movzbl -0x11(%ebp),%eax
     4a1:	3c 0a                	cmp    $0xa,%al
     4a3:	74 16                	je     4bb <gets+0x63>
     4a5:	0f b6 45 ef          	movzbl -0x11(%ebp),%eax
     4a9:	3c 0d                	cmp    $0xd,%al
     4ab:	74 0e                	je     4bb <gets+0x63>
gets(char *buf, int max)
{
  int i, cc;
  char c;

  for(i=0; i+1 < max; ){
     4ad:	8b 45 f4             	mov    -0xc(%ebp),%eax
     4b0:	83 c0 01             	add    $0x1,%eax
     4b3:	3b 45 0c             	cmp    0xc(%ebp),%eax
     4b6:	7c af                	jl     467 <gets+0xf>
     4b8:	eb 01                	jmp    4bb <gets+0x63>
    cc = read(0, &c, 1);
    if(cc < 1)
      break;
     4ba:	90                   	nop
    buf[i++] = c;
    if(c == '\n' || c == '\r')
      break;
  }
  buf[i] = '\0';
     4bb:	8b 55 f4             	mov    -0xc(%ebp),%edx
     4be:	8b 45 08             	mov    0x8(%ebp),%eax
     4c1:	01 d0                	add    %edx,%eax
     4c3:	c6 00 00             	movb   $0x0,(%eax)
  return buf;
     4c6:	8b 45 08             	mov    0x8(%ebp),%eax
}
     4c9:	c9                   	leave  
     4ca:	c3                   	ret    

000004cb <stat>:

int
stat(char *n, struct stat *st)
{
     4cb:	55                   	push   %ebp
     4cc:	89 e5                	mov    %esp,%ebp
     4ce:	83 ec 28             	sub    $0x28,%esp
  int fd;
  int r;

  fd = open(n, O_RDONLY);
     4d1:	c7 44 24 04 00 00 00 	movl   $0x0,0x4(%esp)
     4d8:	00 
     4d9:	8b 45 08             	mov    0x8(%ebp),%eax
     4dc:	89 04 24             	mov    %eax,(%esp)
     4df:	e8 04 01 00 00       	call   5e8 <open>
     4e4:	89 45 f4             	mov    %eax,-0xc(%ebp)
  if(fd < 0)
     4e7:	83 7d f4 00          	cmpl   $0x0,-0xc(%ebp)
     4eb:	79 07                	jns    4f4 <stat+0x29>
    return -1;
     4ed:	b8 ff ff ff ff       	mov    $0xffffffff,%eax
     4f2:	eb 23                	jmp    517 <stat+0x4c>
  r = fstat(fd, st);
     4f4:	8b 45 0c             	mov    0xc(%ebp),%eax
     4f7:	89 44 24 04          	mov    %eax,0x4(%esp)
     4fb:	8b 45 f4             	mov    -0xc(%ebp),%eax
     4fe:	89 04 24             	mov    %eax,(%esp)
     501:	e8 fa 00 00 00       	call   600 <fstat>
     506:	89 45 f0             	mov    %eax,-0x10(%ebp)
  close(fd);
     509:	8b 45 f4             	mov    -0xc(%ebp),%eax
     50c:	89 04 24             	mov    %eax,(%esp)
     50f:	e8 bc 00 00 00       	call   5d0 <close>
  return r;
     514:	8b 45 f0             	mov    -0x10(%ebp),%eax
}
     517:	c9                   	leave  
     518:	c3                   	ret    

00000519 <atoi>:

int
atoi(const char *s)
{
     519:	55                   	push   %ebp
     51a:	89 e5                	mov    %esp,%ebp
     51c:	83 ec 10             	sub    $0x10,%esp
  int n;

  n = 0;
     51f:	c7 45 fc 00 00 00 00 	movl   $0x0,-0x4(%ebp)
  while('0' <= *s && *s <= '9')
     526:	eb 23                	jmp    54b <atoi+0x32>
    n = n*10 + *s++ - '0';
     528:	8b 55 fc             	mov    -0x4(%ebp),%edx
     52b:	89 d0                	mov    %edx,%eax
     52d:	c1 e0 02             	shl    $0x2,%eax
     530:	01 d0                	add    %edx,%eax
     532:	01 c0                	add    %eax,%eax
     534:	89 c2                	mov    %eax,%edx
     536:	8b 45 08             	mov    0x8(%ebp),%eax
     539:	0f b6 00             	movzbl (%eax),%eax
     53c:	0f be c0             	movsbl %al,%eax
     53f:	01 d0                	add    %edx,%eax
     541:	83 e8 30             	sub    $0x30,%eax
     544:	89 45 fc             	mov    %eax,-0x4(%ebp)
     547:	83 45 08 01          	addl   $0x1,0x8(%ebp)
atoi(const char *s)
{
  int n;

  n = 0;
  while('0' <= *s && *s <= '9')
     54b:	8b 45 08             	mov    0x8(%ebp),%eax
     54e:	0f b6 00             	movzbl (%eax),%eax
     551:	3c 2f                	cmp    $0x2f,%al
     553:	7e 0a                	jle    55f <atoi+0x46>
     555:	8b 45 08             	mov    0x8(%ebp),%eax
     558:	0f b6 00             	movzbl (%eax),%eax
     55b:	3c 39                	cmp    $0x39,%al
     55d:	7e c9                	jle    528 <atoi+0xf>
    n = n*10 + *s++ - '0';
  return n;
     55f:	8b 45 fc             	mov    -0x4(%ebp),%eax
}
     562:	c9                   	leave  
     563:	c3                   	ret    

00000564 <memmove>:

void*
memmove(void *vdst, void *vsrc, int n)
{
     564:	55                   	push   %ebp
     565:	89 e5                	mov    %esp,%ebp
     567:	83 ec 10             	sub    $0x10,%esp
  char *dst, *src;
  
  dst = vdst;
     56a:	8b 45 08             	mov    0x8(%ebp),%eax
     56d:	89 45 fc             	mov    %eax,-0x4(%ebp)
  src = vsrc;
     570:	8b 45 0c             	mov    0xc(%ebp),%eax
     573:	89 45 f8             	mov    %eax,-0x8(%ebp)
  while(n-- > 0)
     576:	eb 13                	jmp    58b <memmove+0x27>
    *dst++ = *src++;
     578:	8b 45 f8             	mov    -0x8(%ebp),%eax
     57b:	0f b6 10             	movzbl (%eax),%edx
     57e:	8b 45 fc             	mov    -0x4(%ebp),%eax
     581:	88 10                	mov    %dl,(%eax)
     583:	83 45 fc 01          	addl   $0x1,-0x4(%ebp)
     587:	83 45 f8 01          	addl   $0x1,-0x8(%ebp)
{
  char *dst, *src;
  
  dst = vdst;
  src = vsrc;
  while(n-- > 0)
     58b:	83 7d 10 00          	cmpl   $0x0,0x10(%ebp)
     58f:	0f 9f c0             	setg   %al
     592:	83 6d 10 01          	subl   $0x1,0x10(%ebp)
     596:	84 c0                	test   %al,%al
     598:	75 de                	jne    578 <memmove+0x14>
    *dst++ = *src++;
  return vdst;
     59a:	8b 45 08             	mov    0x8(%ebp),%eax
}
     59d:	c9                   	leave  
     59e:	c3                   	ret    
     59f:	90                   	nop

000005a0 <fork>:
  name: \
    movl $SYS_ ## name, %eax; \
    int $T_SYSCALL; \
    ret

SYSCALL(fork)
     5a0:	b8 01 00 00 00       	mov    $0x1,%eax
     5a5:	cd 40                	int    $0x40
     5a7:	c3                   	ret    

000005a8 <exit>:
SYSCALL(exit)
     5a8:	b8 02 00 00 00       	mov    $0x2,%eax
     5ad:	cd 40                	int    $0x40
     5af:	c3                   	ret    

000005b0 <wait>:
SYSCALL(wait)
     5b0:	b8 03 00 00 00       	mov    $0x3,%eax
     5b5:	cd 40                	int    $0x40
     5b7:	c3                   	ret    

000005b8 <pipe>:
SYSCALL(pipe)
     5b8:	b8 04 00 00 00       	mov    $0x4,%eax
     5bd:	cd 40                	int    $0x40
     5bf:	c3                   	ret    

000005c0 <read>:
SYSCALL(read)
     5c0:	b8 05 00 00 00       	mov    $0x5,%eax
     5c5:	cd 40                	int    $0x40
     5c7:	c3                   	ret    

000005c8 <write>:
SYSCALL(write)
     5c8:	b8 10 00 00 00       	mov    $0x10,%eax
     5cd:	cd 40                	int    $0x40
     5cf:	c3                   	ret    

000005d0 <close>:
SYSCALL(close)
     5d0:	b8 15 00 00 00       	mov    $0x15,%eax
     5d5:	cd 40                	int    $0x40
     5d7:	c3                   	ret    

000005d8 <kill>:
SYSCALL(kill)
     5d8:	b8 06 00 00 00       	mov    $0x6,%eax
     5dd:	cd 40                	int    $0x40
     5df:	c3                   	ret    

000005e0 <exec>:
SYSCALL(exec)
     5e0:	b8 07 00 00 00       	mov    $0x7,%eax
     5e5:	cd 40                	int    $0x40
     5e7:	c3                   	ret    

000005e8 <open>:
SYSCALL(open)
     5e8:	b8 0f 00 00 00       	mov    $0xf,%eax
     5ed:	cd 40                	int    $0x40
     5ef:	c3                   	ret    

000005f0 <mknod>:
SYSCALL(mknod)
     5f0:	b8 11 00 00 00       	mov    $0x11,%eax
     5f5:	cd 40                	int    $0x40
     5f7:	c3                   	ret    

000005f8 <unlink>:
SYSCALL(unlink)
     5f8:	b8 12 00 00 00       	mov    $0x12,%eax
     5fd:	cd 40                	int    $0x40
     5ff:	c3                   	ret    

00000600 <fstat>:
SYSCALL(fstat)
     600:	b8 08 00 00 00       	mov    $0x8,%eax
     605:	cd 40                	int    $0x40
     607:	c3                   	ret    

00000608 <link>:
SYSCALL(link)
     608:	b8 13 00 00 00       	mov    $0x13,%eax
     60d:	cd 40                	int    $0x40
     60f:	c3                   	ret    

00000610 <mkdir>:
SYSCALL(mkdir)
     610:	b8 14 00 00 00       	mov    $0x14,%eax
     615:	cd 40                	int    $0x40
     617:	c3                   	ret    

00000618 <chdir>:
SYSCALL(chdir)
     618:	b8 09 00 00 00       	mov    $0x9,%eax
     61d:	cd 40                	int    $0x40
     61f:	c3                   	ret    

00000620 <dup>:
SYSCALL(dup)
     620:	b8 0a 00 00 00       	mov    $0xa,%eax
     625:	cd 40                	int    $0x40
     627:	c3                   	ret    

00000628 <getpid>:
SYSCALL(getpid)
     628:	b8 0b 00 00 00       	mov    $0xb,%eax
     62d:	cd 40                	int    $0x40
     62f:	c3                   	ret    

00000630 <sbrk>:
SYSCALL(sbrk)
     630:	b8 0c 00 00 00       	mov    $0xc,%eax
     635:	cd 40                	int    $0x40
     637:	c3                   	ret    

00000638 <sleep>:
SYSCALL(sleep)
     638:	b8 0d 00 00 00       	mov    $0xd,%eax
     63d:	cd 40                	int    $0x40
     63f:	c3                   	ret    

00000640 <uptime>:
SYSCALL(uptime)
     640:	b8 0e 00 00 00       	mov    $0xe,%eax
     645:	cd 40                	int    $0x40
     647:	c3                   	ret    

00000648 <signal>:

//our addition
SYSCALL(signal)
     648:	b8 1f 00 00 00       	mov    $0x1f,%eax
     64d:	cd 40                	int    $0x40
     64f:	c3                   	ret    

00000650 <sigsend>:
SYSCALL(sigsend)
     650:	b8 20 00 00 00       	mov    $0x20,%eax
     655:	cd 40                	int    $0x40
     657:	c3                   	ret    

00000658 <alarm>:
SYSCALL(alarm)
     658:	b8 21 00 00 00       	mov    $0x21,%eax
     65d:	cd 40                	int    $0x40
     65f:	c3                   	ret    

00000660 <getTicks>:
SYSCALL(getTicks)
     660:	b8 22 00 00 00       	mov    $0x22,%eax
     665:	cd 40                	int    $0x40
     667:	c3                   	ret    

00000668 <putc>:
#include "stat.h"
#include "user.h"

static void
putc(int fd, char c)
{
     668:	55                   	push   %ebp
     669:	89 e5                	mov    %esp,%ebp
     66b:	83 ec 28             	sub    $0x28,%esp
     66e:	8b 45 0c             	mov    0xc(%ebp),%eax
     671:	88 45 f4             	mov    %al,-0xc(%ebp)
  write(fd, &c, 1);
     674:	c7 44 24 08 01 00 00 	movl   $0x1,0x8(%esp)
     67b:	00 
     67c:	8d 45 f4             	lea    -0xc(%ebp),%eax
     67f:	89 44 24 04          	mov    %eax,0x4(%esp)
     683:	8b 45 08             	mov    0x8(%ebp),%eax
     686:	89 04 24             	mov    %eax,(%esp)
     689:	e8 3a ff ff ff       	call   5c8 <write>
}
     68e:	c9                   	leave  
     68f:	c3                   	ret    

00000690 <printint>:

static void
printint(int fd, int xx, int base, int sgn)
{
     690:	55                   	push   %ebp
     691:	89 e5                	mov    %esp,%ebp
     693:	83 ec 48             	sub    $0x48,%esp
  static char digits[] = "0123456789ABCDEF";
  char buf[16];
  int i, neg;
  uint x;

  neg = 0;
     696:	c7 45 f0 00 00 00 00 	movl   $0x0,-0x10(%ebp)
  if(sgn && xx < 0){
     69d:	83 7d 14 00          	cmpl   $0x0,0x14(%ebp)
     6a1:	74 17                	je     6ba <printint+0x2a>
     6a3:	83 7d 0c 00          	cmpl   $0x0,0xc(%ebp)
     6a7:	79 11                	jns    6ba <printint+0x2a>
    neg = 1;
     6a9:	c7 45 f0 01 00 00 00 	movl   $0x1,-0x10(%ebp)
    x = -xx;
     6b0:	8b 45 0c             	mov    0xc(%ebp),%eax
     6b3:	f7 d8                	neg    %eax
     6b5:	89 45 ec             	mov    %eax,-0x14(%ebp)
     6b8:	eb 06                	jmp    6c0 <printint+0x30>
  } else {
    x = xx;
     6ba:	8b 45 0c             	mov    0xc(%ebp),%eax
     6bd:	89 45 ec             	mov    %eax,-0x14(%ebp)
  }

  i = 0;
     6c0:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
  do{
    buf[i++] = digits[x % base];
     6c7:	8b 4d 10             	mov    0x10(%ebp),%ecx
     6ca:	8b 45 ec             	mov    -0x14(%ebp),%eax
     6cd:	ba 00 00 00 00       	mov    $0x0,%edx
     6d2:	f7 f1                	div    %ecx
     6d4:	89 d0                	mov    %edx,%eax
     6d6:	0f b6 80 14 17 00 00 	movzbl 0x1714(%eax),%eax
     6dd:	8d 4d dc             	lea    -0x24(%ebp),%ecx
     6e0:	8b 55 f4             	mov    -0xc(%ebp),%edx
     6e3:	01 ca                	add    %ecx,%edx
     6e5:	88 02                	mov    %al,(%edx)
     6e7:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
  }while((x /= base) != 0);
     6eb:	8b 55 10             	mov    0x10(%ebp),%edx
     6ee:	89 55 d4             	mov    %edx,-0x2c(%ebp)
     6f1:	8b 45 ec             	mov    -0x14(%ebp),%eax
     6f4:	ba 00 00 00 00       	mov    $0x0,%edx
     6f9:	f7 75 d4             	divl   -0x2c(%ebp)
     6fc:	89 45 ec             	mov    %eax,-0x14(%ebp)
     6ff:	83 7d ec 00          	cmpl   $0x0,-0x14(%ebp)
     703:	75 c2                	jne    6c7 <printint+0x37>
  if(neg)
     705:	83 7d f0 00          	cmpl   $0x0,-0x10(%ebp)
     709:	74 2e                	je     739 <printint+0xa9>
    buf[i++] = '-';
     70b:	8d 55 dc             	lea    -0x24(%ebp),%edx
     70e:	8b 45 f4             	mov    -0xc(%ebp),%eax
     711:	01 d0                	add    %edx,%eax
     713:	c6 00 2d             	movb   $0x2d,(%eax)
     716:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)

  while(--i >= 0)
     71a:	eb 1d                	jmp    739 <printint+0xa9>
    putc(fd, buf[i]);
     71c:	8d 55 dc             	lea    -0x24(%ebp),%edx
     71f:	8b 45 f4             	mov    -0xc(%ebp),%eax
     722:	01 d0                	add    %edx,%eax
     724:	0f b6 00             	movzbl (%eax),%eax
     727:	0f be c0             	movsbl %al,%eax
     72a:	89 44 24 04          	mov    %eax,0x4(%esp)
     72e:	8b 45 08             	mov    0x8(%ebp),%eax
     731:	89 04 24             	mov    %eax,(%esp)
     734:	e8 2f ff ff ff       	call   668 <putc>
    buf[i++] = digits[x % base];
  }while((x /= base) != 0);
  if(neg)
    buf[i++] = '-';

  while(--i >= 0)
     739:	83 6d f4 01          	subl   $0x1,-0xc(%ebp)
     73d:	83 7d f4 00          	cmpl   $0x0,-0xc(%ebp)
     741:	79 d9                	jns    71c <printint+0x8c>
    putc(fd, buf[i]);
}
     743:	c9                   	leave  
     744:	c3                   	ret    

00000745 <printf>:

// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, char *fmt, ...)
{
     745:	55                   	push   %ebp
     746:	89 e5                	mov    %esp,%ebp
     748:	83 ec 38             	sub    $0x38,%esp
  char *s;
  int c, i, state;
  uint *ap;

  state = 0;
     74b:	c7 45 ec 00 00 00 00 	movl   $0x0,-0x14(%ebp)
  ap = (uint*)(void*)&fmt + 1;
     752:	8d 45 0c             	lea    0xc(%ebp),%eax
     755:	83 c0 04             	add    $0x4,%eax
     758:	89 45 e8             	mov    %eax,-0x18(%ebp)
  for(i = 0; fmt[i]; i++){
     75b:	c7 45 f0 00 00 00 00 	movl   $0x0,-0x10(%ebp)
     762:	e9 7d 01 00 00       	jmp    8e4 <printf+0x19f>
    c = fmt[i] & 0xff;
     767:	8b 55 0c             	mov    0xc(%ebp),%edx
     76a:	8b 45 f0             	mov    -0x10(%ebp),%eax
     76d:	01 d0                	add    %edx,%eax
     76f:	0f b6 00             	movzbl (%eax),%eax
     772:	0f be c0             	movsbl %al,%eax
     775:	25 ff 00 00 00       	and    $0xff,%eax
     77a:	89 45 e4             	mov    %eax,-0x1c(%ebp)
    if(state == 0){
     77d:	83 7d ec 00          	cmpl   $0x0,-0x14(%ebp)
     781:	75 2c                	jne    7af <printf+0x6a>
      if(c == '%'){
     783:	83 7d e4 25          	cmpl   $0x25,-0x1c(%ebp)
     787:	75 0c                	jne    795 <printf+0x50>
        state = '%';
     789:	c7 45 ec 25 00 00 00 	movl   $0x25,-0x14(%ebp)
     790:	e9 4b 01 00 00       	jmp    8e0 <printf+0x19b>
      } else {
        putc(fd, c);
     795:	8b 45 e4             	mov    -0x1c(%ebp),%eax
     798:	0f be c0             	movsbl %al,%eax
     79b:	89 44 24 04          	mov    %eax,0x4(%esp)
     79f:	8b 45 08             	mov    0x8(%ebp),%eax
     7a2:	89 04 24             	mov    %eax,(%esp)
     7a5:	e8 be fe ff ff       	call   668 <putc>
     7aa:	e9 31 01 00 00       	jmp    8e0 <printf+0x19b>
      }
    } else if(state == '%'){
     7af:	83 7d ec 25          	cmpl   $0x25,-0x14(%ebp)
     7b3:	0f 85 27 01 00 00    	jne    8e0 <printf+0x19b>
      if(c == 'd'){
     7b9:	83 7d e4 64          	cmpl   $0x64,-0x1c(%ebp)
     7bd:	75 2d                	jne    7ec <printf+0xa7>
        printint(fd, *ap, 10, 1);
     7bf:	8b 45 e8             	mov    -0x18(%ebp),%eax
     7c2:	8b 00                	mov    (%eax),%eax
     7c4:	c7 44 24 0c 01 00 00 	movl   $0x1,0xc(%esp)
     7cb:	00 
     7cc:	c7 44 24 08 0a 00 00 	movl   $0xa,0x8(%esp)
     7d3:	00 
     7d4:	89 44 24 04          	mov    %eax,0x4(%esp)
     7d8:	8b 45 08             	mov    0x8(%ebp),%eax
     7db:	89 04 24             	mov    %eax,(%esp)
     7de:	e8 ad fe ff ff       	call   690 <printint>
        ap++;
     7e3:	83 45 e8 04          	addl   $0x4,-0x18(%ebp)
     7e7:	e9 ed 00 00 00       	jmp    8d9 <printf+0x194>
      } else if(c == 'x' || c == 'p'){
     7ec:	83 7d e4 78          	cmpl   $0x78,-0x1c(%ebp)
     7f0:	74 06                	je     7f8 <printf+0xb3>
     7f2:	83 7d e4 70          	cmpl   $0x70,-0x1c(%ebp)
     7f6:	75 2d                	jne    825 <printf+0xe0>
        printint(fd, *ap, 16, 0);
     7f8:	8b 45 e8             	mov    -0x18(%ebp),%eax
     7fb:	8b 00                	mov    (%eax),%eax
     7fd:	c7 44 24 0c 00 00 00 	movl   $0x0,0xc(%esp)
     804:	00 
     805:	c7 44 24 08 10 00 00 	movl   $0x10,0x8(%esp)
     80c:	00 
     80d:	89 44 24 04          	mov    %eax,0x4(%esp)
     811:	8b 45 08             	mov    0x8(%ebp),%eax
     814:	89 04 24             	mov    %eax,(%esp)
     817:	e8 74 fe ff ff       	call   690 <printint>
        ap++;
     81c:	83 45 e8 04          	addl   $0x4,-0x18(%ebp)
     820:	e9 b4 00 00 00       	jmp    8d9 <printf+0x194>
      } else if(c == 's'){
     825:	83 7d e4 73          	cmpl   $0x73,-0x1c(%ebp)
     829:	75 46                	jne    871 <printf+0x12c>
        s = (char*)*ap;
     82b:	8b 45 e8             	mov    -0x18(%ebp),%eax
     82e:	8b 00                	mov    (%eax),%eax
     830:	89 45 f4             	mov    %eax,-0xc(%ebp)
        ap++;
     833:	83 45 e8 04          	addl   $0x4,-0x18(%ebp)
        if(s == 0)
     837:	83 7d f4 00          	cmpl   $0x0,-0xc(%ebp)
     83b:	75 27                	jne    864 <printf+0x11f>
          s = "(null)";
     83d:	c7 45 f4 17 12 00 00 	movl   $0x1217,-0xc(%ebp)
        while(*s != 0){
     844:	eb 1e                	jmp    864 <printf+0x11f>
          putc(fd, *s);
     846:	8b 45 f4             	mov    -0xc(%ebp),%eax
     849:	0f b6 00             	movzbl (%eax),%eax
     84c:	0f be c0             	movsbl %al,%eax
     84f:	89 44 24 04          	mov    %eax,0x4(%esp)
     853:	8b 45 08             	mov    0x8(%ebp),%eax
     856:	89 04 24             	mov    %eax,(%esp)
     859:	e8 0a fe ff ff       	call   668 <putc>
          s++;
     85e:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
     862:	eb 01                	jmp    865 <printf+0x120>
      } else if(c == 's'){
        s = (char*)*ap;
        ap++;
        if(s == 0)
          s = "(null)";
        while(*s != 0){
     864:	90                   	nop
     865:	8b 45 f4             	mov    -0xc(%ebp),%eax
     868:	0f b6 00             	movzbl (%eax),%eax
     86b:	84 c0                	test   %al,%al
     86d:	75 d7                	jne    846 <printf+0x101>
     86f:	eb 68                	jmp    8d9 <printf+0x194>
          putc(fd, *s);
          s++;
        }
      } else if(c == 'c'){
     871:	83 7d e4 63          	cmpl   $0x63,-0x1c(%ebp)
     875:	75 1d                	jne    894 <printf+0x14f>
        putc(fd, *ap);
     877:	8b 45 e8             	mov    -0x18(%ebp),%eax
     87a:	8b 00                	mov    (%eax),%eax
     87c:	0f be c0             	movsbl %al,%eax
     87f:	89 44 24 04          	mov    %eax,0x4(%esp)
     883:	8b 45 08             	mov    0x8(%ebp),%eax
     886:	89 04 24             	mov    %eax,(%esp)
     889:	e8 da fd ff ff       	call   668 <putc>
        ap++;
     88e:	83 45 e8 04          	addl   $0x4,-0x18(%ebp)
     892:	eb 45                	jmp    8d9 <printf+0x194>
      } else if(c == '%'){
     894:	83 7d e4 25          	cmpl   $0x25,-0x1c(%ebp)
     898:	75 17                	jne    8b1 <printf+0x16c>
        putc(fd, c);
     89a:	8b 45 e4             	mov    -0x1c(%ebp),%eax
     89d:	0f be c0             	movsbl %al,%eax
     8a0:	89 44 24 04          	mov    %eax,0x4(%esp)
     8a4:	8b 45 08             	mov    0x8(%ebp),%eax
     8a7:	89 04 24             	mov    %eax,(%esp)
     8aa:	e8 b9 fd ff ff       	call   668 <putc>
     8af:	eb 28                	jmp    8d9 <printf+0x194>
      } else {
        // Unknown % sequence.  Print it to draw attention.
        putc(fd, '%');
     8b1:	c7 44 24 04 25 00 00 	movl   $0x25,0x4(%esp)
     8b8:	00 
     8b9:	8b 45 08             	mov    0x8(%ebp),%eax
     8bc:	89 04 24             	mov    %eax,(%esp)
     8bf:	e8 a4 fd ff ff       	call   668 <putc>
        putc(fd, c);
     8c4:	8b 45 e4             	mov    -0x1c(%ebp),%eax
     8c7:	0f be c0             	movsbl %al,%eax
     8ca:	89 44 24 04          	mov    %eax,0x4(%esp)
     8ce:	8b 45 08             	mov    0x8(%ebp),%eax
     8d1:	89 04 24             	mov    %eax,(%esp)
     8d4:	e8 8f fd ff ff       	call   668 <putc>
      }
      state = 0;
     8d9:	c7 45 ec 00 00 00 00 	movl   $0x0,-0x14(%ebp)
  int c, i, state;
  uint *ap;

  state = 0;
  ap = (uint*)(void*)&fmt + 1;
  for(i = 0; fmt[i]; i++){
     8e0:	83 45 f0 01          	addl   $0x1,-0x10(%ebp)
     8e4:	8b 55 0c             	mov    0xc(%ebp),%edx
     8e7:	8b 45 f0             	mov    -0x10(%ebp),%eax
     8ea:	01 d0                	add    %edx,%eax
     8ec:	0f b6 00             	movzbl (%eax),%eax
     8ef:	84 c0                	test   %al,%al
     8f1:	0f 85 70 fe ff ff    	jne    767 <printf+0x22>
        putc(fd, c);
      }
      state = 0;
    }
  }
}
     8f7:	c9                   	leave  
     8f8:	c3                   	ret    
     8f9:	66 90                	xchg   %ax,%ax
     8fb:	90                   	nop

000008fc <free>:
static Header base;
static Header *freep;

void
free(void *ap)
{
     8fc:	55                   	push   %ebp
     8fd:	89 e5                	mov    %esp,%ebp
     8ff:	83 ec 10             	sub    $0x10,%esp
  Header *bp, *p;

  bp = (Header*)ap - 1;
     902:	8b 45 08             	mov    0x8(%ebp),%eax
     905:	83 e8 08             	sub    $0x8,%eax
     908:	89 45 f8             	mov    %eax,-0x8(%ebp)
  for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
     90b:	a1 48 17 00 00       	mov    0x1748,%eax
     910:	89 45 fc             	mov    %eax,-0x4(%ebp)
     913:	eb 24                	jmp    939 <free+0x3d>
    if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
     915:	8b 45 fc             	mov    -0x4(%ebp),%eax
     918:	8b 00                	mov    (%eax),%eax
     91a:	3b 45 fc             	cmp    -0x4(%ebp),%eax
     91d:	77 12                	ja     931 <free+0x35>
     91f:	8b 45 f8             	mov    -0x8(%ebp),%eax
     922:	3b 45 fc             	cmp    -0x4(%ebp),%eax
     925:	77 24                	ja     94b <free+0x4f>
     927:	8b 45 fc             	mov    -0x4(%ebp),%eax
     92a:	8b 00                	mov    (%eax),%eax
     92c:	3b 45 f8             	cmp    -0x8(%ebp),%eax
     92f:	77 1a                	ja     94b <free+0x4f>
free(void *ap)
{
  Header *bp, *p;

  bp = (Header*)ap - 1;
  for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
     931:	8b 45 fc             	mov    -0x4(%ebp),%eax
     934:	8b 00                	mov    (%eax),%eax
     936:	89 45 fc             	mov    %eax,-0x4(%ebp)
     939:	8b 45 f8             	mov    -0x8(%ebp),%eax
     93c:	3b 45 fc             	cmp    -0x4(%ebp),%eax
     93f:	76 d4                	jbe    915 <free+0x19>
     941:	8b 45 fc             	mov    -0x4(%ebp),%eax
     944:	8b 00                	mov    (%eax),%eax
     946:	3b 45 f8             	cmp    -0x8(%ebp),%eax
     949:	76 ca                	jbe    915 <free+0x19>
    if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
      break;
  if(bp + bp->s.size == p->s.ptr){
     94b:	8b 45 f8             	mov    -0x8(%ebp),%eax
     94e:	8b 40 04             	mov    0x4(%eax),%eax
     951:	8d 14 c5 00 00 00 00 	lea    0x0(,%eax,8),%edx
     958:	8b 45 f8             	mov    -0x8(%ebp),%eax
     95b:	01 c2                	add    %eax,%edx
     95d:	8b 45 fc             	mov    -0x4(%ebp),%eax
     960:	8b 00                	mov    (%eax),%eax
     962:	39 c2                	cmp    %eax,%edx
     964:	75 24                	jne    98a <free+0x8e>
    bp->s.size += p->s.ptr->s.size;
     966:	8b 45 f8             	mov    -0x8(%ebp),%eax
     969:	8b 50 04             	mov    0x4(%eax),%edx
     96c:	8b 45 fc             	mov    -0x4(%ebp),%eax
     96f:	8b 00                	mov    (%eax),%eax
     971:	8b 40 04             	mov    0x4(%eax),%eax
     974:	01 c2                	add    %eax,%edx
     976:	8b 45 f8             	mov    -0x8(%ebp),%eax
     979:	89 50 04             	mov    %edx,0x4(%eax)
    bp->s.ptr = p->s.ptr->s.ptr;
     97c:	8b 45 fc             	mov    -0x4(%ebp),%eax
     97f:	8b 00                	mov    (%eax),%eax
     981:	8b 10                	mov    (%eax),%edx
     983:	8b 45 f8             	mov    -0x8(%ebp),%eax
     986:	89 10                	mov    %edx,(%eax)
     988:	eb 0a                	jmp    994 <free+0x98>
  } else
    bp->s.ptr = p->s.ptr;
     98a:	8b 45 fc             	mov    -0x4(%ebp),%eax
     98d:	8b 10                	mov    (%eax),%edx
     98f:	8b 45 f8             	mov    -0x8(%ebp),%eax
     992:	89 10                	mov    %edx,(%eax)
  if(p + p->s.size == bp){
     994:	8b 45 fc             	mov    -0x4(%ebp),%eax
     997:	8b 40 04             	mov    0x4(%eax),%eax
     99a:	8d 14 c5 00 00 00 00 	lea    0x0(,%eax,8),%edx
     9a1:	8b 45 fc             	mov    -0x4(%ebp),%eax
     9a4:	01 d0                	add    %edx,%eax
     9a6:	3b 45 f8             	cmp    -0x8(%ebp),%eax
     9a9:	75 20                	jne    9cb <free+0xcf>
    p->s.size += bp->s.size;
     9ab:	8b 45 fc             	mov    -0x4(%ebp),%eax
     9ae:	8b 50 04             	mov    0x4(%eax),%edx
     9b1:	8b 45 f8             	mov    -0x8(%ebp),%eax
     9b4:	8b 40 04             	mov    0x4(%eax),%eax
     9b7:	01 c2                	add    %eax,%edx
     9b9:	8b 45 fc             	mov    -0x4(%ebp),%eax
     9bc:	89 50 04             	mov    %edx,0x4(%eax)
    p->s.ptr = bp->s.ptr;
     9bf:	8b 45 f8             	mov    -0x8(%ebp),%eax
     9c2:	8b 10                	mov    (%eax),%edx
     9c4:	8b 45 fc             	mov    -0x4(%ebp),%eax
     9c7:	89 10                	mov    %edx,(%eax)
     9c9:	eb 08                	jmp    9d3 <free+0xd7>
  } else
    p->s.ptr = bp;
     9cb:	8b 45 fc             	mov    -0x4(%ebp),%eax
     9ce:	8b 55 f8             	mov    -0x8(%ebp),%edx
     9d1:	89 10                	mov    %edx,(%eax)
  freep = p;
     9d3:	8b 45 fc             	mov    -0x4(%ebp),%eax
     9d6:	a3 48 17 00 00       	mov    %eax,0x1748
}
     9db:	c9                   	leave  
     9dc:	c3                   	ret    

000009dd <morecore>:

static Header*
morecore(uint nu)
{
     9dd:	55                   	push   %ebp
     9de:	89 e5                	mov    %esp,%ebp
     9e0:	83 ec 28             	sub    $0x28,%esp
  char *p;
  Header *hp;

  if(nu < 4096)
     9e3:	81 7d 08 ff 0f 00 00 	cmpl   $0xfff,0x8(%ebp)
     9ea:	77 07                	ja     9f3 <morecore+0x16>
    nu = 4096;
     9ec:	c7 45 08 00 10 00 00 	movl   $0x1000,0x8(%ebp)
  p = sbrk(nu * sizeof(Header));
     9f3:	8b 45 08             	mov    0x8(%ebp),%eax
     9f6:	c1 e0 03             	shl    $0x3,%eax
     9f9:	89 04 24             	mov    %eax,(%esp)
     9fc:	e8 2f fc ff ff       	call   630 <sbrk>
     a01:	89 45 f4             	mov    %eax,-0xc(%ebp)
  if(p == (char*)-1)
     a04:	83 7d f4 ff          	cmpl   $0xffffffff,-0xc(%ebp)
     a08:	75 07                	jne    a11 <morecore+0x34>
    return 0;
     a0a:	b8 00 00 00 00       	mov    $0x0,%eax
     a0f:	eb 22                	jmp    a33 <morecore+0x56>
  hp = (Header*)p;
     a11:	8b 45 f4             	mov    -0xc(%ebp),%eax
     a14:	89 45 f0             	mov    %eax,-0x10(%ebp)
  hp->s.size = nu;
     a17:	8b 45 f0             	mov    -0x10(%ebp),%eax
     a1a:	8b 55 08             	mov    0x8(%ebp),%edx
     a1d:	89 50 04             	mov    %edx,0x4(%eax)
  free((void*)(hp + 1));
     a20:	8b 45 f0             	mov    -0x10(%ebp),%eax
     a23:	83 c0 08             	add    $0x8,%eax
     a26:	89 04 24             	mov    %eax,(%esp)
     a29:	e8 ce fe ff ff       	call   8fc <free>
  return freep;
     a2e:	a1 48 17 00 00       	mov    0x1748,%eax
}
     a33:	c9                   	leave  
     a34:	c3                   	ret    

00000a35 <malloc>:

void*
malloc(uint nbytes)
{
     a35:	55                   	push   %ebp
     a36:	89 e5                	mov    %esp,%ebp
     a38:	83 ec 28             	sub    $0x28,%esp
  Header *p, *prevp;
  uint nunits;

  nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
     a3b:	8b 45 08             	mov    0x8(%ebp),%eax
     a3e:	83 c0 07             	add    $0x7,%eax
     a41:	c1 e8 03             	shr    $0x3,%eax
     a44:	83 c0 01             	add    $0x1,%eax
     a47:	89 45 ec             	mov    %eax,-0x14(%ebp)
  if((prevp = freep) == 0){
     a4a:	a1 48 17 00 00       	mov    0x1748,%eax
     a4f:	89 45 f0             	mov    %eax,-0x10(%ebp)
     a52:	83 7d f0 00          	cmpl   $0x0,-0x10(%ebp)
     a56:	75 23                	jne    a7b <malloc+0x46>
    base.s.ptr = freep = prevp = &base;
     a58:	c7 45 f0 40 17 00 00 	movl   $0x1740,-0x10(%ebp)
     a5f:	8b 45 f0             	mov    -0x10(%ebp),%eax
     a62:	a3 48 17 00 00       	mov    %eax,0x1748
     a67:	a1 48 17 00 00       	mov    0x1748,%eax
     a6c:	a3 40 17 00 00       	mov    %eax,0x1740
    base.s.size = 0;
     a71:	c7 05 44 17 00 00 00 	movl   $0x0,0x1744
     a78:	00 00 00 
  }
  for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
     a7b:	8b 45 f0             	mov    -0x10(%ebp),%eax
     a7e:	8b 00                	mov    (%eax),%eax
     a80:	89 45 f4             	mov    %eax,-0xc(%ebp)
    if(p->s.size >= nunits){
     a83:	8b 45 f4             	mov    -0xc(%ebp),%eax
     a86:	8b 40 04             	mov    0x4(%eax),%eax
     a89:	3b 45 ec             	cmp    -0x14(%ebp),%eax
     a8c:	72 4d                	jb     adb <malloc+0xa6>
      if(p->s.size == nunits)
     a8e:	8b 45 f4             	mov    -0xc(%ebp),%eax
     a91:	8b 40 04             	mov    0x4(%eax),%eax
     a94:	3b 45 ec             	cmp    -0x14(%ebp),%eax
     a97:	75 0c                	jne    aa5 <malloc+0x70>
        prevp->s.ptr = p->s.ptr;
     a99:	8b 45 f4             	mov    -0xc(%ebp),%eax
     a9c:	8b 10                	mov    (%eax),%edx
     a9e:	8b 45 f0             	mov    -0x10(%ebp),%eax
     aa1:	89 10                	mov    %edx,(%eax)
     aa3:	eb 26                	jmp    acb <malloc+0x96>
      else {
        p->s.size -= nunits;
     aa5:	8b 45 f4             	mov    -0xc(%ebp),%eax
     aa8:	8b 40 04             	mov    0x4(%eax),%eax
     aab:	89 c2                	mov    %eax,%edx
     aad:	2b 55 ec             	sub    -0x14(%ebp),%edx
     ab0:	8b 45 f4             	mov    -0xc(%ebp),%eax
     ab3:	89 50 04             	mov    %edx,0x4(%eax)
        p += p->s.size;
     ab6:	8b 45 f4             	mov    -0xc(%ebp),%eax
     ab9:	8b 40 04             	mov    0x4(%eax),%eax
     abc:	c1 e0 03             	shl    $0x3,%eax
     abf:	01 45 f4             	add    %eax,-0xc(%ebp)
        p->s.size = nunits;
     ac2:	8b 45 f4             	mov    -0xc(%ebp),%eax
     ac5:	8b 55 ec             	mov    -0x14(%ebp),%edx
     ac8:	89 50 04             	mov    %edx,0x4(%eax)
      }
      freep = prevp;
     acb:	8b 45 f0             	mov    -0x10(%ebp),%eax
     ace:	a3 48 17 00 00       	mov    %eax,0x1748
      return (void*)(p + 1);
     ad3:	8b 45 f4             	mov    -0xc(%ebp),%eax
     ad6:	83 c0 08             	add    $0x8,%eax
     ad9:	eb 38                	jmp    b13 <malloc+0xde>
    }
    if(p == freep)
     adb:	a1 48 17 00 00       	mov    0x1748,%eax
     ae0:	39 45 f4             	cmp    %eax,-0xc(%ebp)
     ae3:	75 1b                	jne    b00 <malloc+0xcb>
      if((p = morecore(nunits)) == 0)
     ae5:	8b 45 ec             	mov    -0x14(%ebp),%eax
     ae8:	89 04 24             	mov    %eax,(%esp)
     aeb:	e8 ed fe ff ff       	call   9dd <morecore>
     af0:	89 45 f4             	mov    %eax,-0xc(%ebp)
     af3:	83 7d f4 00          	cmpl   $0x0,-0xc(%ebp)
     af7:	75 07                	jne    b00 <malloc+0xcb>
        return 0;
     af9:	b8 00 00 00 00       	mov    $0x0,%eax
     afe:	eb 13                	jmp    b13 <malloc+0xde>
  nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
  if((prevp = freep) == 0){
    base.s.ptr = freep = prevp = &base;
    base.s.size = 0;
  }
  for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
     b00:	8b 45 f4             	mov    -0xc(%ebp),%eax
     b03:	89 45 f0             	mov    %eax,-0x10(%ebp)
     b06:	8b 45 f4             	mov    -0xc(%ebp),%eax
     b09:	8b 00                	mov    (%eax),%eax
     b0b:	89 45 f4             	mov    %eax,-0xc(%ebp)
      return (void*)(p + 1);
    }
    if(p == freep)
      if((p = morecore(nunits)) == 0)
        return 0;
  }
     b0e:	e9 70 ff ff ff       	jmp    a83 <malloc+0x4e>
}
     b13:	c9                   	leave  
     b14:	c3                   	ret    
     b15:	66 90                	xchg   %ax,%ax
     b17:	90                   	nop

00000b18 <uthread_init>:
int c_thread = 0;

// task 2.2

void uthread_init()
{
     b18:	55                   	push   %ebp
     b19:	89 e5                	mov    %esp,%ebp
     b1b:	83 ec 28             	sub    $0x28,%esp

	int i;
	ttable[0].tid = 0;
     b1e:	c7 05 c0 17 00 00 00 	movl   $0x0,0x17c0
     b25:	00 00 00 
	STORE_ESP(ttable[0].esp);
     b28:	89 e0                	mov    %esp,%eax
     b2a:	a3 c4 17 00 00       	mov    %eax,0x17c4
	STORE_EBP(ttable[0].ebp);
     b2f:	89 e8                	mov    %ebp,%eax
     b31:	a3 c8 17 00 00       	mov    %eax,0x17c8
	ttable[0].state = T_RUNNING;
     b36:	c7 05 d0 17 00 00 01 	movl   $0x1,0x17d0
     b3d:	00 00 00 
	ttable[0].wait_num = 0;
     b40:	c7 05 d4 18 00 00 00 	movl   $0x0,0x18d4
     b47:	00 00 00 
	//initialize all other slots to FREE and assign TIDs for future use
	for (i = 1; i < MAX_THREAD; i ++)
     b4a:	c7 45 f4 01 00 00 00 	movl   $0x1,-0xc(%ebp)
     b51:	eb 2c                	jmp    b7f <uthread_init+0x67>
	{
		ttable[i].tid = i;
     b53:	8b 45 f4             	mov    -0xc(%ebp),%eax
     b56:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     b5c:	8d 90 c0 17 00 00    	lea    0x17c0(%eax),%edx
     b62:	8b 45 f4             	mov    -0xc(%ebp),%eax
     b65:	89 02                	mov    %eax,(%edx)
		ttable[i].state = T_FREE;
     b67:	8b 45 f4             	mov    -0xc(%ebp),%eax
     b6a:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     b70:	05 d0 17 00 00       	add    $0x17d0,%eax
     b75:	c7 00 00 00 00 00    	movl   $0x0,(%eax)
	STORE_ESP(ttable[0].esp);
	STORE_EBP(ttable[0].ebp);
	ttable[0].state = T_RUNNING;
	ttable[0].wait_num = 0;
	//initialize all other slots to FREE and assign TIDs for future use
	for (i = 1; i < MAX_THREAD; i ++)
     b7b:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
     b7f:	83 7d f4 3f          	cmpl   $0x3f,-0xc(%ebp)
     b83:	7e ce                	jle    b53 <uthread_init+0x3b>
	{
		ttable[i].tid = i;
		ttable[i].state = T_FREE;
	}
	signal(SIGALRM, uthread_yield);
     b85:	c7 44 24 04 0b 0e 00 	movl   $0xe0b,0x4(%esp)
     b8c:	00 
     b8d:	c7 04 24 0e 00 00 00 	movl   $0xe,(%esp)
     b94:	e8 af fa ff ff       	call   648 <signal>
	alarm(THREAD_QUANTA);
     b99:	c7 04 24 05 00 00 00 	movl   $0x5,(%esp)
     ba0:	e8 b3 fa ff ff       	call   658 <alarm>
}
     ba5:	c9                   	leave  
     ba6:	c3                   	ret    

00000ba7 <uthread_create>:

// task 2.3

int uthread_create(void (*start_func)(void *), void*arg)
{
     ba7:	55                   	push   %ebp
     ba8:	89 e5                	mov    %esp,%ebp
     baa:	83 ec 28             	sub    $0x28,%esp
	int i;
	int ticks;
	asm("pusha");
     bad:	60                   	pusha  
	ticks = getTicks();
     bae:	e8 ad fa ff ff       	call   660 <getTicks>
     bb3:	89 45 f0             	mov    %eax,-0x10(%ebp)
	alarm(0);
     bb6:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
     bbd:	e8 96 fa ff ff       	call   658 <alarm>
	asm("popa");
     bc2:	61                   	popa   
	for (i = 0; i < MAX_THREAD; i++)
     bc3:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
     bca:	e9 02 01 00 00       	jmp    cd1 <uthread_create+0x12a>
	{
		if (ttable[i].state == T_FREE)
     bcf:	8b 45 f4             	mov    -0xc(%ebp),%eax
     bd2:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     bd8:	05 d0 17 00 00       	add    $0x17d0,%eax
     bdd:	8b 00                	mov    (%eax),%eax
     bdf:	85 c0                	test   %eax,%eax
     be1:	0f 85 e6 00 00 00    	jne    ccd <uthread_create+0x126>
		{	
			//allocate a stack for the new thread
			if ((ttable[i].stack = malloc(STACK_SIZE)) < 0)
     be7:	c7 04 24 00 10 00 00 	movl   $0x1000,(%esp)
     bee:	e8 42 fe ff ff       	call   a35 <malloc>
     bf3:	8b 55 f4             	mov    -0xc(%ebp),%edx
     bf6:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
     bfc:	81 c2 c0 17 00 00    	add    $0x17c0,%edx
     c02:	89 42 0c             	mov    %eax,0xc(%edx)
			{
				alarm(ticks);
				return -1;
			}
			LOAD_ESP(ttable[i].stack + STACK_SIZE);
     c05:	8b 45 f4             	mov    -0xc(%ebp),%eax
     c08:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     c0e:	05 c0 17 00 00       	add    $0x17c0,%eax
     c13:	8b 40 0c             	mov    0xc(%eax),%eax
     c16:	05 00 10 00 00       	add    $0x1000,%eax
     c1b:	89 c4                	mov    %eax,%esp
			PUSH(arg);
     c1d:	8b 45 0c             	mov    0xc(%ebp),%eax
     c20:	89 c7                	mov    %eax,%edi
     c22:	57                   	push   %edi
			PUSH(uthread_exit);
     c23:	b8 91 0e 00 00       	mov    $0xe91,%eax
     c28:	89 c7                	mov    %eax,%edi
     c2a:	57                   	push   %edi
			PUSH(start_func);
     c2b:	8b 45 08             	mov    0x8(%ebp),%eax
     c2e:	89 c7                	mov    %eax,%edi
     c30:	57                   	push   %edi
			//added for the first "pop ebp"
			PUSH(0);
     c31:	b8 00 00 00 00       	mov    $0x0,%eax
     c36:	89 c7                	mov    %eax,%edi
     c38:	57                   	push   %edi
			STORE_ESP(ttable[i].ebp);
     c39:	89 e0                	mov    %esp,%eax
     c3b:	8b 55 f4             	mov    -0xc(%ebp),%edx
     c3e:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
     c44:	81 c2 c0 17 00 00    	add    $0x17c0,%edx
     c4a:	89 42 08             	mov    %eax,0x8(%edx)
			ttable[i].esp = ttable[i].ebp;
     c4d:	8b 45 f4             	mov    -0xc(%ebp),%eax
     c50:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     c56:	05 c0 17 00 00       	add    $0x17c0,%eax
     c5b:	8b 40 08             	mov    0x8(%eax),%eax
     c5e:	8b 55 f4             	mov    -0xc(%ebp),%edx
     c61:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
     c67:	81 c2 c0 17 00 00    	add    $0x17c0,%edx
     c6d:	89 42 04             	mov    %eax,0x4(%edx)
			//set esp to current thread's esp
			LOAD_ESP(ttable[c_thread].esp);
     c70:	a1 4c 17 00 00       	mov    0x174c,%eax
     c75:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     c7b:	05 c0 17 00 00       	add    $0x17c0,%eax
     c80:	8b 40 04             	mov    0x4(%eax),%eax
     c83:	89 c4                	mov    %eax,%esp
			ttable[i].state = T_RUNNABLE;
     c85:	8b 45 f4             	mov    -0xc(%ebp),%eax
     c88:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     c8e:	05 d0 17 00 00       	add    $0x17d0,%eax
     c93:	c7 00 02 00 00 00    	movl   $0x2,(%eax)
			ttable[i].wait_num = 0;
     c99:	8b 45 f4             	mov    -0xc(%ebp),%eax
     c9c:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     ca2:	05 d0 18 00 00       	add    $0x18d0,%eax
     ca7:	c7 40 04 00 00 00 00 	movl   $0x0,0x4(%eax)
			asm("pusha");
     cae:	60                   	pusha  
			alarm(ticks);
     caf:	8b 45 f0             	mov    -0x10(%ebp),%eax
     cb2:	89 04 24             	mov    %eax,(%esp)
     cb5:	e8 9e f9 ff ff       	call   658 <alarm>
			asm("popa");
     cba:	61                   	popa   
			return ttable[i].tid;
     cbb:	8b 45 f4             	mov    -0xc(%ebp),%eax
     cbe:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     cc4:	05 c0 17 00 00       	add    $0x17c0,%eax
     cc9:	8b 00                	mov    (%eax),%eax
     ccb:	eb 1e                	jmp    ceb <uthread_create+0x144>
	int ticks;
	asm("pusha");
	ticks = getTicks();
	alarm(0);
	asm("popa");
	for (i = 0; i < MAX_THREAD; i++)
     ccd:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
     cd1:	83 7d f4 3f          	cmpl   $0x3f,-0xc(%ebp)
     cd5:	0f 8e f4 fe ff ff    	jle    bcf <uthread_create+0x28>
			asm("popa");
			return ttable[i].tid;
			
		}
	}
	alarm(ticks);
     cdb:	8b 45 f0             	mov    -0x10(%ebp),%eax
     cde:	89 04 24             	mov    %eax,(%esp)
     ce1:	e8 72 f9 ff ff       	call   658 <alarm>
	//failed - no free thread to use
	return -1;
     ce6:	b8 ff ff ff ff       	mov    $0xffffffff,%eax
}
     ceb:	c9                   	leave  
     cec:	c3                   	ret    

00000ced <safe_exit>:

// task 2.4


void safe_exit()
{
     ced:	55                   	push   %ebp
     cee:	89 e5                	mov    %esp,%ebp
     cf0:	83 ec 28             	sub    $0x28,%esp
     cf3:	eb 01                	jmp    cf6 <safe_exit+0x9>
			}
		}
		if (tid == MAX_THREAD){
			exit();
		}
	}
     cf5:	90                   	nop
void safe_exit()
{
	int tid;
	while (1)
	{
		for (tid = 1; tid< MAX_THREAD; tid++)
     cf6:	c7 45 f4 01 00 00 00 	movl   $0x1,-0xc(%ebp)
     cfd:	eb 25                	jmp    d24 <safe_exit+0x37>
		{
			if (ttable[tid].state != T_FREE){
     cff:	8b 45 f4             	mov    -0xc(%ebp),%eax
     d02:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     d08:	05 d0 17 00 00       	add    $0x17d0,%eax
     d0d:	8b 00                	mov    (%eax),%eax
     d0f:	85 c0                	test   %eax,%eax
     d11:	74 0d                	je     d20 <safe_exit+0x33>
				uthread_join(tid);
     d13:	8b 45 f4             	mov    -0xc(%ebp),%eax
     d16:	89 04 24             	mov    %eax,(%esp)
     d19:	e8 1d 02 00 00       	call   f3b <uthread_join>
				break;
     d1e:	eb 0a                	jmp    d2a <safe_exit+0x3d>
void safe_exit()
{
	int tid;
	while (1)
	{
		for (tid = 1; tid< MAX_THREAD; tid++)
     d20:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
     d24:	83 7d f4 3f          	cmpl   $0x3f,-0xc(%ebp)
     d28:	7e d5                	jle    cff <safe_exit+0x12>
			if (ttable[tid].state != T_FREE){
				uthread_join(tid);
				break;
			}
		}
		if (tid == MAX_THREAD){
     d2a:	83 7d f4 40          	cmpl   $0x40,-0xc(%ebp)
     d2e:	75 c5                	jne    cf5 <safe_exit+0x8>
			exit();
     d30:	e8 73 f8 ff ff       	call   5a8 <exit>

00000d35 <uthread_switch>:
		}
	}
}

void uthread_switch()
{
     d35:	55                   	push   %ebp
     d36:	89 e5                	mov    %esp,%ebp
     d38:	83 ec 28             	sub    $0x28,%esp
	int i;
	int n_thread = (c_thread + 1) % MAX_THREAD;
     d3b:	a1 4c 17 00 00       	mov    0x174c,%eax
     d40:	8d 50 01             	lea    0x1(%eax),%edx
     d43:	89 d0                	mov    %edx,%eax
     d45:	c1 f8 1f             	sar    $0x1f,%eax
     d48:	c1 e8 1a             	shr    $0x1a,%eax
     d4b:	01 c2                	add    %eax,%edx
     d4d:	83 e2 3f             	and    $0x3f,%edx
     d50:	89 d1                	mov    %edx,%ecx
     d52:	29 c1                	sub    %eax,%ecx
     d54:	89 c8                	mov    %ecx,%eax
     d56:	89 45 f0             	mov    %eax,-0x10(%ebp)

	//finding a runnable thread
	for (i = 0; ttable[n_thread].state != T_RUNNABLE && i < MAX_THREAD; i++)
     d59:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
     d60:	eb 20                	jmp    d82 <uthread_switch+0x4d>
	{
		n_thread = (n_thread + 1) % MAX_THREAD;
     d62:	8b 45 f0             	mov    -0x10(%ebp),%eax
     d65:	8d 50 01             	lea    0x1(%eax),%edx
     d68:	89 d0                	mov    %edx,%eax
     d6a:	c1 f8 1f             	sar    $0x1f,%eax
     d6d:	c1 e8 1a             	shr    $0x1a,%eax
     d70:	01 c2                	add    %eax,%edx
     d72:	83 e2 3f             	and    $0x3f,%edx
     d75:	89 d1                	mov    %edx,%ecx
     d77:	29 c1                	sub    %eax,%ecx
     d79:	89 c8                	mov    %ecx,%eax
     d7b:	89 45 f0             	mov    %eax,-0x10(%ebp)
{
	int i;
	int n_thread = (c_thread + 1) % MAX_THREAD;

	//finding a runnable thread
	for (i = 0; ttable[n_thread].state != T_RUNNABLE && i < MAX_THREAD; i++)
     d7e:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
     d82:	8b 45 f0             	mov    -0x10(%ebp),%eax
     d85:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     d8b:	05 d0 17 00 00       	add    $0x17d0,%eax
     d90:	8b 00                	mov    (%eax),%eax
     d92:	83 f8 02             	cmp    $0x2,%eax
     d95:	74 06                	je     d9d <uthread_switch+0x68>
     d97:	83 7d f4 3f          	cmpl   $0x3f,-0xc(%ebp)
     d9b:	7e c5                	jle    d62 <uthread_switch+0x2d>
	{
		n_thread = (n_thread + 1) % MAX_THREAD;
	}
	STORE_ESP(ttable[c_thread].esp);
     d9d:	8b 15 4c 17 00 00    	mov    0x174c,%edx
     da3:	89 e0                	mov    %esp,%eax
     da5:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
     dab:	81 c2 c0 17 00 00    	add    $0x17c0,%edx
     db1:	89 42 04             	mov    %eax,0x4(%edx)
	STORE_EBP(ttable[c_thread].ebp);
     db4:	8b 15 4c 17 00 00    	mov    0x174c,%edx
     dba:	89 e8                	mov    %ebp,%eax
     dbc:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
     dc2:	81 c2 c0 17 00 00    	add    $0x17c0,%edx
     dc8:	89 42 08             	mov    %eax,0x8(%edx)
	c_thread = n_thread;
     dcb:	8b 45 f0             	mov    -0x10(%ebp),%eax
     dce:	a3 4c 17 00 00       	mov    %eax,0x174c
	LOAD_EBP(ttable[c_thread].ebp);
     dd3:	a1 4c 17 00 00       	mov    0x174c,%eax
     dd8:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     dde:	05 c0 17 00 00       	add    $0x17c0,%eax
     de3:	8b 40 08             	mov    0x8(%eax),%eax
     de6:	89 c5                	mov    %eax,%ebp
	LOAD_ESP(ttable[c_thread].esp);
     de8:	a1 4c 17 00 00       	mov    0x174c,%eax
     ded:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     df3:	05 c0 17 00 00       	add    $0x17c0,%eax
     df8:	8b 40 04             	mov    0x4(%eax),%eax
     dfb:	89 c4                	mov    %eax,%esp
	alarm(THREAD_QUANTA);
     dfd:	c7 04 24 05 00 00 00 	movl   $0x5,(%esp)
     e04:	e8 4f f8 ff ff       	call   658 <alarm>
}
     e09:	c9                   	leave  
     e0a:	c3                   	ret    

00000e0b <uthread_yield>:

void uthread_yield()
{
     e0b:	55                   	push   %ebp
     e0c:	89 e5                	mov    %esp,%ebp
     e0e:	83 ec 18             	sub    $0x18,%esp
	//store registers on stack
	asm("pusha");
     e11:	60                   	pusha  
	alarm(0);
     e12:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
     e19:	e8 3a f8 ff ff       	call   658 <alarm>
	ttable[c_thread].state = T_RUNNABLE;
     e1e:	a1 4c 17 00 00       	mov    0x174c,%eax
     e23:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     e29:	05 d0 17 00 00       	add    $0x17d0,%eax
     e2e:	c7 00 02 00 00 00    	movl   $0x2,(%eax)
	//change current thread
	uthread_switch();
     e34:	e8 fc fe ff ff       	call   d35 <uthread_switch>
	asm("popa");
     e39:	61                   	popa   
}
     e3a:	c9                   	leave  
     e3b:	c3                   	ret    

00000e3c <uthread_awake>:

// task 2.5

void uthread_awake()
{
     e3c:	55                   	push   %ebp
     e3d:	89 e5                	mov    %esp,%ebp
     e3f:	83 ec 10             	sub    $0x10,%esp
	int i;
	for (i = 0; i < ttable[c_thread].wait_num; i++)
     e42:	c7 45 fc 00 00 00 00 	movl   $0x0,-0x4(%ebp)
     e49:	eb 2c                	jmp    e77 <uthread_awake+0x3b>
		ttable[ttable[c_thread].waiting[i]].state = T_RUNNABLE;
     e4b:	a1 4c 17 00 00       	mov    0x174c,%eax
     e50:	6b d0 46             	imul   $0x46,%eax,%edx
     e53:	8b 45 fc             	mov    -0x4(%ebp),%eax
     e56:	01 d0                	add    %edx,%eax
     e58:	83 c0 04             	add    $0x4,%eax
     e5b:	8b 04 85 c4 17 00 00 	mov    0x17c4(,%eax,4),%eax
     e62:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     e68:	05 d0 17 00 00       	add    $0x17d0,%eax
     e6d:	c7 00 02 00 00 00    	movl   $0x2,(%eax)
// task 2.5

void uthread_awake()
{
	int i;
	for (i = 0; i < ttable[c_thread].wait_num; i++)
     e73:	83 45 fc 01          	addl   $0x1,-0x4(%ebp)
     e77:	a1 4c 17 00 00       	mov    0x174c,%eax
     e7c:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     e82:	05 d0 18 00 00       	add    $0x18d0,%eax
     e87:	8b 40 04             	mov    0x4(%eax),%eax
     e8a:	3b 45 fc             	cmp    -0x4(%ebp),%eax
     e8d:	7f bc                	jg     e4b <uthread_awake+0xf>
		ttable[ttable[c_thread].waiting[i]].state = T_RUNNABLE;
}
     e8f:	c9                   	leave  
     e90:	c3                   	ret    

00000e91 <uthread_exit>:

void uthread_exit()
{
     e91:	55                   	push   %ebp
     e92:	89 e5                	mov    %esp,%ebp
     e94:	83 ec 18             	sub    $0x18,%esp
	asm("pusha");
     e97:	60                   	pusha  
	alarm(0);
     e98:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
     e9f:	e8 b4 f7 ff ff       	call   658 <alarm>
	asm("popa");
     ea4:	61                   	popa   
	ttable[c_thread].state = T_FREE;
     ea5:	a1 4c 17 00 00       	mov    0x174c,%eax
     eaa:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     eb0:	05 d0 17 00 00       	add    $0x17d0,%eax
     eb5:	c7 00 00 00 00 00    	movl   $0x0,(%eax)
	if (ttable[c_thread].tid != 0)
     ebb:	a1 4c 17 00 00       	mov    0x174c,%eax
     ec0:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     ec6:	05 c0 17 00 00       	add    $0x17c0,%eax
     ecb:	8b 00                	mov    (%eax),%eax
     ecd:	85 c0                	test   %eax,%eax
     ecf:	74 1d                	je     eee <uthread_exit+0x5d>
		free(ttable[c_thread].stack);
     ed1:	a1 4c 17 00 00       	mov    0x174c,%eax
     ed6:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     edc:	05 c0 17 00 00       	add    $0x17c0,%eax
     ee1:	8b 40 0c             	mov    0xc(%eax),%eax
     ee4:	89 04 24             	mov    %eax,(%esp)
     ee7:	e8 10 fa ff ff       	call   8fc <free>
     eec:	eb 05                	jmp    ef3 <uthread_exit+0x62>
	else
		safe_exit();
     eee:	e8 fa fd ff ff       	call   ced <safe_exit>
	uthread_awake();
     ef3:	e8 44 ff ff ff       	call   e3c <uthread_awake>
	uthread_switch();
     ef8:	e8 38 fe ff ff       	call   d35 <uthread_switch>
	asm("popa");
     efd:	61                   	popa   
}
     efe:	c9                   	leave  
     eff:	c3                   	ret    

00000f00 <uthread_self>:

// task 2.6

int uthread_self()
{
     f00:	55                   	push   %ebp
     f01:	89 e5                	mov    %esp,%ebp
	return c_thread;
     f03:	a1 4c 17 00 00       	mov    0x174c,%eax
}
     f08:	5d                   	pop    %ebp
     f09:	c3                   	ret    

00000f0a <uthread_sleep>:

// task 2.7

void uthread_sleep()
{
     f0a:	55                   	push   %ebp
     f0b:	89 e5                	mov    %esp,%ebp
     f0d:	83 ec 18             	sub    $0x18,%esp
	asm("pusha");
     f10:	60                   	pusha  
	alarm(0);
     f11:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
     f18:	e8 3b f7 ff ff       	call   658 <alarm>
	ttable[c_thread].state = T_SLEEPING;
     f1d:	a1 4c 17 00 00       	mov    0x174c,%eax
     f22:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     f28:	05 d0 17 00 00       	add    $0x17d0,%eax
     f2d:	c7 00 03 00 00 00    	movl   $0x3,(%eax)
	uthread_switch();
     f33:	e8 fd fd ff ff       	call   d35 <uthread_switch>
	asm("popa");
     f38:	61                   	popa   
}
     f39:	c9                   	leave  
     f3a:	c3                   	ret    

00000f3b <uthread_join>:

int uthread_join(int tid)
{
     f3b:	55                   	push   %ebp
     f3c:	89 e5                	mov    %esp,%ebp
     f3e:	53                   	push   %ebx
     f3f:	83 ec 24             	sub    $0x24,%esp

	int ticks;
	asm("pusha");
     f42:	60                   	pusha  
	ticks = getTicks();
     f43:	e8 18 f7 ff ff       	call   660 <getTicks>
     f48:	89 45 f4             	mov    %eax,-0xc(%ebp)
	alarm(0);
     f4b:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
     f52:	e8 01 f7 ff ff       	call   658 <alarm>
	asm("popa");
     f57:	61                   	popa   
	if (ttable[tid].state != T_FREE)
     f58:	8b 45 08             	mov    0x8(%ebp),%eax
     f5b:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     f61:	05 d0 17 00 00       	add    $0x17d0,%eax
     f66:	8b 00                	mov    (%eax),%eax
     f68:	85 c0                	test   %eax,%eax
     f6a:	74 5e                	je     fca <uthread_join+0x8f>
	{
		//adding current thread to tid waiting list and going to sleep.
		ttable[tid].waiting[ttable[tid].wait_num++] = ttable[c_thread].tid;
     f6c:	8b 45 08             	mov    0x8(%ebp),%eax
     f6f:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     f75:	05 10 01 00 00       	add    $0x110,%eax
     f7a:	05 c0 17 00 00       	add    $0x17c0,%eax
     f7f:	8d 48 04             	lea    0x4(%eax),%ecx
     f82:	8b 45 08             	mov    0x8(%ebp),%eax
     f85:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     f8b:	05 d0 18 00 00       	add    $0x18d0,%eax
     f90:	8b 40 04             	mov    0x4(%eax),%eax
     f93:	8b 15 4c 17 00 00    	mov    0x174c,%edx
     f99:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
     f9f:	81 c2 c0 17 00 00    	add    $0x17c0,%edx
     fa5:	8b 12                	mov    (%edx),%edx
     fa7:	8b 5d 08             	mov    0x8(%ebp),%ebx
     faa:	6b db 46             	imul   $0x46,%ebx,%ebx
     fad:	01 c3                	add    %eax,%ebx
     faf:	83 c3 04             	add    $0x4,%ebx
     fb2:	89 14 9d c4 17 00 00 	mov    %edx,0x17c4(,%ebx,4)
     fb9:	83 c0 01             	add    $0x1,%eax
     fbc:	89 01                	mov    %eax,(%ecx)
		uthread_sleep();
     fbe:	e8 47 ff ff ff       	call   f0a <uthread_sleep>
		return 0;
     fc3:	b8 00 00 00 00       	mov    $0x0,%eax
     fc8:	eb 12                	jmp    fdc <uthread_join+0xa1>
	}
	asm("pusha");
     fca:	60                   	pusha  
	alarm(ticks);
     fcb:	8b 45 f4             	mov    -0xc(%ebp),%eax
     fce:	89 04 24             	mov    %eax,(%esp)
     fd1:	e8 82 f6 ff ff       	call   658 <alarm>
	asm("popa");
     fd6:	61                   	popa   
	return -1;
     fd7:	b8 ff ff ff ff       	mov    $0xffffffff,%eax
}
     fdc:	83 c4 24             	add    $0x24,%esp
     fdf:	5b                   	pop    %ebx
     fe0:	5d                   	pop    %ebp
     fe1:	c3                   	ret    

00000fe2 <queue_init>:

void queue_init(struct tqueue *q)
{
     fe2:	55                   	push   %ebp
     fe3:	89 e5                	mov    %esp,%ebp
	q->head = 0;
     fe5:	8b 45 08             	mov    0x8(%ebp),%eax
     fe8:	c7 80 00 01 00 00 00 	movl   $0x0,0x100(%eax)
     fef:	00 00 00 
	q->tail = 0;
     ff2:	8b 45 08             	mov    0x8(%ebp),%eax
     ff5:	c7 80 04 01 00 00 00 	movl   $0x0,0x104(%eax)
     ffc:	00 00 00 
}
     fff:	5d                   	pop    %ebp
    1000:	c3                   	ret    

00001001 <dequeue>:

struct uthread* dequeue(struct binary_semaphore* semaphore)
{
    1001:	55                   	push   %ebp
    1002:	89 e5                	mov    %esp,%ebp
    1004:	57                   	push   %edi
    1005:	56                   	push   %esi
    1006:	53                   	push   %ebx
	if (semaphore->queue->head == semaphore->queue->tail)
    1007:	8b 45 08             	mov    0x8(%ebp),%eax
    100a:	8b 00                	mov    (%eax),%eax
    100c:	8b 90 00 01 00 00    	mov    0x100(%eax),%edx
    1012:	8b 45 08             	mov    0x8(%ebp),%eax
    1015:	8b 00                	mov    (%eax),%eax
    1017:	8b 80 04 01 00 00    	mov    0x104(%eax),%eax
    101d:	39 c2                	cmp    %eax,%edx
    101f:	75 07                	jne    1028 <dequeue+0x27>
		return 0;
    1021:	b9 00 00 00 00       	mov    $0x0,%ecx
    1026:	eb 31                	jmp    1059 <dequeue+0x58>
	return semaphore->queue->uthreads[semaphore->queue->tail++ % MAX_THREAD];
    1028:	8b 45 08             	mov    0x8(%ebp),%eax
    102b:	8b 18                	mov    (%eax),%ebx
    102d:	8b 45 08             	mov    0x8(%ebp),%eax
    1030:	8b 10                	mov    (%eax),%edx
    1032:	8b 82 04 01 00 00    	mov    0x104(%edx),%eax
    1038:	89 c1                	mov    %eax,%ecx
    103a:	c1 f9 1f             	sar    $0x1f,%ecx
    103d:	c1 e9 1a             	shr    $0x1a,%ecx
    1040:	8d 34 08             	lea    (%eax,%ecx,1),%esi
    1043:	83 e6 3f             	and    $0x3f,%esi
    1046:	89 f7                	mov    %esi,%edi
    1048:	29 cf                	sub    %ecx,%edi
    104a:	89 f9                	mov    %edi,%ecx
    104c:	8b 0c 8b             	mov    (%ebx,%ecx,4),%ecx
    104f:	83 c0 01             	add    $0x1,%eax
    1052:	89 82 04 01 00 00    	mov    %eax,0x104(%edx)
    1058:	90                   	nop
    1059:	89 c8                	mov    %ecx,%eax
}
    105b:	5b                   	pop    %ebx
    105c:	5e                   	pop    %esi
    105d:	5f                   	pop    %edi
    105e:	5d                   	pop    %ebp
    105f:	c3                   	ret    

00001060 <enqueue>:

void enqueue(struct binary_semaphore* semaphore)
{
    1060:	55                   	push   %ebp
    1061:	89 e5                	mov    %esp,%ebp
    1063:	57                   	push   %edi
    1064:	56                   	push   %esi
    1065:	53                   	push   %ebx
	semaphore->queue->uthreads[semaphore->queue->head++ % MAX_THREAD] = &ttable[c_thread];
    1066:	8b 45 08             	mov    0x8(%ebp),%eax
    1069:	8b 18                	mov    (%eax),%ebx
    106b:	8b 45 08             	mov    0x8(%ebp),%eax
    106e:	8b 10                	mov    (%eax),%edx
    1070:	8b 82 00 01 00 00    	mov    0x100(%edx),%eax
    1076:	89 c1                	mov    %eax,%ecx
    1078:	c1 f9 1f             	sar    $0x1f,%ecx
    107b:	c1 e9 1a             	shr    $0x1a,%ecx
    107e:	8d 34 08             	lea    (%eax,%ecx,1),%esi
    1081:	83 e6 3f             	and    $0x3f,%esi
    1084:	89 f7                	mov    %esi,%edi
    1086:	29 cf                	sub    %ecx,%edi
    1088:	89 f9                	mov    %edi,%ecx
    108a:	8b 35 4c 17 00 00    	mov    0x174c,%esi
    1090:	69 f6 18 01 00 00    	imul   $0x118,%esi,%esi
    1096:	81 c6 c0 17 00 00    	add    $0x17c0,%esi
    109c:	89 34 8b             	mov    %esi,(%ebx,%ecx,4)
    109f:	83 c0 01             	add    $0x1,%eax
    10a2:	89 82 00 01 00 00    	mov    %eax,0x100(%edx)
}
    10a8:	5b                   	pop    %ebx
    10a9:	5e                   	pop    %esi
    10aa:	5f                   	pop    %edi
    10ab:	5d                   	pop    %ebp
    10ac:	c3                   	ret    

000010ad <binary_semaphore_init>:

void binary_semaphore_init(struct binary_semaphore* semaphore, int value)
{
    10ad:	55                   	push   %ebp
    10ae:	89 e5                	mov    %esp,%ebp
    10b0:	83 ec 18             	sub    $0x18,%esp
	semaphore->queue = malloc(sizeof(struct tqueue));
    10b3:	c7 04 24 08 01 00 00 	movl   $0x108,(%esp)
    10ba:	e8 76 f9 ff ff       	call   a35 <malloc>
    10bf:	8b 55 08             	mov    0x8(%ebp),%edx
    10c2:	89 02                	mov    %eax,(%edx)
	if (!value)
    10c4:	83 7d 0c 00          	cmpl   $0x0,0xc(%ebp)
    10c8:	75 0c                	jne    10d6 <binary_semaphore_init+0x29>
		semaphore->state = S_LOCKED;
    10ca:	8b 45 08             	mov    0x8(%ebp),%eax
    10cd:	c7 40 04 01 00 00 00 	movl   $0x1,0x4(%eax)
    10d4:	eb 0a                	jmp    10e0 <binary_semaphore_init+0x33>
	else
		semaphore->state = S_FREE;
    10d6:	8b 45 08             	mov    0x8(%ebp),%eax
    10d9:	c7 40 04 00 00 00 00 	movl   $0x0,0x4(%eax)
}
    10e0:	c9                   	leave  
    10e1:	c3                   	ret    

000010e2 <binary_semaphore_down>:
void binary_semaphore_down(struct binary_semaphore* semaphore)
{
    10e2:	55                   	push   %ebp
    10e3:	89 e5                	mov    %esp,%ebp
    10e5:	83 ec 28             	sub    $0x28,%esp
	//store amount of ticks left and prevent scheduler from switching
	int ticks;
	asm("pusha");
    10e8:	60                   	pusha  
	ticks = getTicks();
    10e9:	e8 72 f5 ff ff       	call   660 <getTicks>
    10ee:	89 45 f4             	mov    %eax,-0xc(%ebp)
	alarm(0);
    10f1:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
    10f8:	e8 5b f5 ff ff       	call   658 <alarm>
	asm("popa");
    10fd:	61                   	popa   
	if (semaphore->state == S_LOCKED)
    10fe:	8b 45 08             	mov    0x8(%ebp),%eax
    1101:	8b 40 04             	mov    0x4(%eax),%eax
    1104:	83 f8 01             	cmp    $0x1,%eax
    1107:	75 1c                	jne    1125 <binary_semaphore_down+0x43>
	{
		enqueue(semaphore);
    1109:	8b 45 08             	mov    0x8(%ebp),%eax
    110c:	89 04 24             	mov    %eax,(%esp)
    110f:	e8 4c ff ff ff       	call   1060 <enqueue>
		uthread_sleep();
    1114:	e8 f1 fd ff ff       	call   f0a <uthread_sleep>
		alarm(0);
    1119:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
    1120:	e8 33 f5 ff ff       	call   658 <alarm>
	}
	semaphore->state = S_LOCKED;
    1125:	8b 45 08             	mov    0x8(%ebp),%eax
    1128:	c7 40 04 01 00 00 00 	movl   $0x1,0x4(%eax)
	//allow the thread to run its remaining time
	alarm(ticks);
    112f:	8b 45 f4             	mov    -0xc(%ebp),%eax
    1132:	89 04 24             	mov    %eax,(%esp)
    1135:	e8 1e f5 ff ff       	call   658 <alarm>

}
    113a:	c9                   	leave  
    113b:	c3                   	ret    

0000113c <binary_semaphore_up>:
void binary_semaphore_up(struct binary_semaphore* semaphore)
{
    113c:	55                   	push   %ebp
    113d:	89 e5                	mov    %esp,%ebp
    113f:	83 ec 28             	sub    $0x28,%esp
	int ticks;
	struct uthread *next;
	asm("pusha");
    1142:	60                   	pusha  
	ticks = getTicks();
    1143:	e8 18 f5 ff ff       	call   660 <getTicks>
    1148:	89 45 f4             	mov    %eax,-0xc(%ebp)
	alarm(0);
    114b:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
    1152:	e8 01 f5 ff ff       	call   658 <alarm>
	asm("popa");
    1157:	61                   	popa   


	if ((next = dequeue(semaphore)) == 0)
    1158:	8b 45 08             	mov    0x8(%ebp),%eax
    115b:	89 04 24             	mov    %eax,(%esp)
    115e:	e8 9e fe ff ff       	call   1001 <dequeue>
    1163:	89 45 f0             	mov    %eax,-0x10(%ebp)
    1166:	83 7d f0 00          	cmpl   $0x0,-0x10(%ebp)
    116a:	75 19                	jne    1185 <binary_semaphore_up+0x49>
	{
		//no thread is waiting. release semaphore and restore alarm
		semaphore->state = S_FREE;
    116c:	8b 45 08             	mov    0x8(%ebp),%eax
    116f:	c7 40 04 00 00 00 00 	movl   $0x0,0x4(%eax)
		asm("pusha");
    1176:	60                   	pusha  
		alarm(ticks);
    1177:	8b 45 f4             	mov    -0xc(%ebp),%eax
    117a:	89 04 24             	mov    %eax,(%esp)
    117d:	e8 d6 f4 ff ff       	call   658 <alarm>
		asm("popa");
    1182:	61                   	popa   
    1183:	eb 0f                	jmp    1194 <binary_semaphore_up+0x58>
	}
	else
	{
		//threads are waiting. wake up the next thread and yield.
		next->state = T_RUNNABLE;
    1185:	8b 45 f0             	mov    -0x10(%ebp),%eax
    1188:	c7 40 10 02 00 00 00 	movl   $0x2,0x10(%eax)
		uthread_yield();
    118f:	e8 77 fc ff ff       	call   e0b <uthread_yield>
	}
}
    1194:	c9                   	leave  
    1195:	c3                   	ret    
